expm1

Accurate exp(x) - 1 for small x.

Category: Mathematics > Elementary Math

Syntax

Y = expm1(X)

Returns exp(X) - 1 for each element, without the cancellation error of the direct subtraction.

Description

When x is tiny, exp(x) is very close to 1, and subtracting 1 throws away most of the significant digits. expm1 uses a method that keeps full precision, which matters in interest-rate formulas, decay constants and any code that later divides the result by x.

log1p is the inverse operation: log1p(expm1(x)) returns x.

Input arguments

X
Real array.

Output arguments

Y
Array of the same size as X.

Example

Small arguments

x = 1e-12;
exp(x) - 1
expm1(x)
Output
ans = 1.0001e-12
ans = 1.0000e-12

The direct subtraction is wrong in the fourth digit; expm1 returns 1.0000e-12.

See also

exp log1p log expm