Python math.expm1() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Python 3.2+

Definition

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)
CallWhat 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

ParameterDescription
xRequired positional real number (int or float).

Return Value

Return ValueDescription
floate ** 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}")

How It Works

  1. Visible loss at 1e-16. Adding a number below float epsilon to 1.0 rounds back to 1.0, so math.exp(1e-16) - 1.0 prints zero.
  2. Taylor series accuracy. math.expm1(x) evaluates the shift directly around zero without constructing 1.0 + x.
  3. Scientific formatting. Using :.6e highlights both the scale and the complete collapse of the naive formula.

Example 2 — Measure Small Decay Fractions Per Sensor Tick

Compute the fractional drop 1 - e**(-k*dt) cleanly as -math.expm1(-k * dt).

python
import math

decay_rate = 0.002
for dt in [0.1, 1.0, 10.0]:
    lost = -math.expm1(-decay_rate * dt)
    print(f"dt={dt:>4}s -> fraction_decayed={lost:.6f}")

How It Works

  1. Negate twice. 1 - exp(-a) equals -expm1(-a), avoiding subtraction against 1.0.
  2. Short sensor window. At 0.1s, the decayed fraction stays sharp even far below one percent.
  3. Multi-second accumulation. Longer windows curve gracefully below linear decay_rate * dt.

Example 3 — Check Negative Infinity and Overflow Behavior

Inspect how math.expm1() handles 0, infinities, and overflowing inputs.

python
import math

print(math.expm1(0))
print(math.expm1(float("-inf")))
print(math.expm1(float("inf")))

try:
    math.expm1(1000)
except OverflowError:
    print("expm1(1000) overflows float")

How It Works

  1. Zero stays zero. e**0 - 1 gives exact 0.0.
  2. Asymptote at -1.0. As the exponent approaches negative infinity, e**x vanishes, leaving -1.0.
  3. Same overflow threshold. Positive finite exponents beyond float limits raise OverflowError just like math.exp().

Frequently Asked Questions

It stands for exponential minus one: exp(x) - 1.
When x is tiny, math.exp(x) is very close to 1.0 and rounding destroys low digits before subtraction. math.expm1(x) preserves full precision.
Because e**(-inf) is 0.0, subtracting 1 gives -1.0.
Yes. By IEEE 754 rules, expm1 preserves the sign of signed zero.
math.log1p(y) computes log(1 + y), reversing expm1(x) accurately near zero.

Next: math.fabs()

Return the absolute value of x as a float.

fabs() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful