all Python 3mathterm
math.exp
constants
Returns e raised to the power of x (the exponential). Equivalent to math.e ** x, but more accurate and faster for large x.
Syntax
math.exp(x)
For large arguments this does not quietly return inf — it raises OverflowError: math range error, roughly above x = 710, so either clamp the input or catch it. Underflow in the other direction is silent and just gives 0.0. When you need exp(x) - 1 for tiny x, use math.expm1(x); the plain subtraction throws away almost all significant digits there.
Examples
import math
print(math.exp(0)) # → 1.0
print(math.exp(1)) # → 2.718281828...
print(math.exp(2)) # → 7.389...
print(math.exp(-1)) # → 0.3678...
print(math.exp(10)) # → 22026.465...
print(math.exp(math.log(5))) # → ? (значение зависит от системной libm — карточка учит наличию погрешности, а не её цифрам)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy