math.expm1(x) computes e ** x - 1, matching math.exp(x) - 1 mathematically while staying accurate when x is very close to 0.
Near zero, math.exp(x) rounds near 1.0 and subtracting 1.0 wipes out leading digits. expm1(x) keeps full floating-point precision.
math.expm1() is a function in Python's standard math module: import it with import math and call math.expm1(...), or import the name directly with from math import expm1.
Syntax
Import math and pass a small or regular exponent.
python
import math
delta = math.expm1(x)
Call
What it does
math.expm1(0)
Returns 0.0.
math.expm1(1e-16)
Returns 1e-16 (where exp(1e-16) - 1 gives 0.0).
math.expm1(float("-inf"))
Returns -1.0.
math.expm1(1000)
Raises OverflowError: result exceeds float range.
Added in Python 3.2. Its inverse for small changes near zero is math.log1p().
Function signatures
python
math.expm1(x, /)
# returns: float (e ** x) - 1 with full precision near x = 0
Parameters
Parameter
Description
x
Required positional real number (int or float).
Return Value
Return Value
Description
float
e ** x - 1. Returns inf for inf and -1.0 for -inf.
Python Examples
Example 1 — Avoid Precision Collapse on Tiny Growth Rates
Compare math.exp(x) - 1 against math.expm1(x) as x shrinks toward zero.
python
import math
for x in [1e-5, 1e-10, 1e-16]:
naive = math.exp(x) - 1.0
exact = math.expm1(x)
print(f"x={x:.0e} naive={naive:.6e} expm1={exact:.6e}")