expm1()
expm1(x) Returns:
numeric · Updated March 13, 2026 · Base Functions math expm1 exponential numerical-stability base
The expm1() function computes exp(x) - 1, the exponential of the input minus one. It is more accurate than exp(x) - 1 when x is very small.
Syntax
expm1(x)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
x | numeric | — | A numeric vector or scalar |
Examples
Basic usage
# expm1(0) = exp(0) - 1 = 0
expm1(0)
# [1] 0
# expm1(1) = exp(1) - 1
expm1(1)
# [1] 1.718282
# For very small values, expm1 is more accurate
x <- 1e-10
exp(x) - 1
# [1] 0 # precision lost!
expm1(x)
# [1] 1e-10 # accurate
Numerical stability demonstration
# When x is very small, exp(x) - 1 loses precision
x <- 1e-15
exp(x) - 1
# [1] 0 # precision lost!
expm1(x)
# [1] 1e-15 # accurate
# Relative error comparison
x <- 1e-8
(exp(x) - 1 - x) / x # relative error in exp() - 1
# [1] 5.000001e-08
(expm1(x) - x) / x # relative error in expm1()
# [1] 0
Common Patterns
Financial calculations
# Continuous compounding returns
rate <- 0.0001
principal <- 1000
principal * expm1(rate)
# [1] 0.100005 # accurate for small rates
Probability calculations
# Poisson distribution: P(X = n) = exp(-lambda) * lambda^n / n!
lambda <- 1e-8
1 - exp(-lambda) # P(X > 0)
# [1] 0 # precision lost
expm1(-lambda) # -expm1(-lambda) = P(X > 0)
# [1] -1e-08 # accurate