exponential

Math.expm1

Returns e^x - 1, computed accurately even for very small x. Introduced in ES2015 to avoid catastrophic cancellation near zero.

Math.expm1(x)

Parameters & edge cases

Case Behavior
x The exponent
small x Far more accurate than Math.exp(x) - 1 when |x| is near zero
large x For large x, expm1 and exp effectively return the same value

Examples

console.log(Math.expm1(0));      // 0

e⁰ - 1 = 0 exactly.

console.log(Math.expm1(1));      // 1.718281828459045

e - 1.

console.log(Math.expm1(1e-10));  // 1.00000000005e-10

Precise near zero; Math.exp(1e-10) - 1 loses digits.

console.log(Math.exp(1e-10) - 1); // 1.000000082740371e-10

The naive form is visibly wrong for tiny x.

Gotcha

Only reach for expm1 when your x is close to 0. For x with magnitude > 1e-4, plain `Math.exp(x) - 1` is fine.

Related

← All JS Math methods · Array methods