Exponential function math.exp and cmath.exp
suggest changeBoth the math and cmath modules contain the Euler number: e, and using it with the builtin pow() function or ** operator works mostly like math.exp():
import math
math.e ** 2 # 7.3890560989306495
math.exp(2) # 7.38905609893065
import cmath
cmath.e ** 2 # 7.3890560989306495
cmath.exp(2) # (7.38905609893065+0j)
However, the result differs, and using the exponential function directly is more reliable than builtin exponentiation with base math.e:
print(math.e ** 10) # 22026.465794806703
print(math.exp(10)) # 22026.465794806718
print(cmath.exp(10).real) # 22026.465794806718
# difference starts here ---------------^
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents