import math
print(math.expm1(5)) # 147.4131591025766
print(math.expm1(0)) # 0.0
Using negative number
import math
print(math.expm1(-34.11)) # -0.9999999999999984
print(math.expm1(-34.99)) # -0.9999999999999993
print(math.expm1(-34)) # -0.9999999999999983
import math
print(math.e ** -34.11 -1 ) # -0.9999999999999984
e : is a numerical constant of value equal to 2.71828 import math
x = 1e-10
print(math.exp(x) - 1) # Less accurate due to floating-point rounding
print(math.expm1(x)) # More accurate for small x
import math
x_values = [1, 0.1, 1e-10, -1]
for x in x_values:
print(f"x: {x}, exp(x) - 1: {math.exp(x) - 1}, expm1(x): {math.expm1(x)}")
Output
x: 1, exp(x) - 1: 1.718281828459045, expm1(x): 1.718281828459045
x: 0.1, exp(x) - 1: 0.10517091807564771, expm1(x): 0.10517091807564763
x: 1e-10, exp(x) - 1: 1.000000082740371e-10, expm1(x): 1.00000000005e-10
x: -1, exp(x) - 1: -0.6321205588285577, expm1(x): -0.6321205588285577
import math
principal = 1000 # Principal amount
rate = 0.05 # Annual interest rate
time = 1 # 1 year
# Continuous compound interest
interest = principal * math.expm1(rate * time)
print("Accrued interest:", interest)
Output
Accrued interest: 51.271096376024055
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.