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
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.