exponential
Math.exp
Returns e^x, where e is Euler's number (~2.71828). The inverse of Math.log (the natural logarithm).
Math.exp(x) Parameters & edge cases
| Case | Behavior |
|---|---|
| x | The exponent to raise e to |
| overflow | Math.exp(710) returns Infinity — the double-precision ceiling |
| underflow | Math.exp(-745) rounds to 0 |
Examples
console.log(Math.exp(0)); // 1 e^0 = 1.
console.log(Math.exp(1)); // 2.718281828459045 e^1 = Math.E.
console.log(Math.exp(2)); // 7.38905609893065 e² — used often in growth and softmax.
console.log(Math.exp(-1)); // 0.36787944117144233 1/e — for exponential decay.
Gotcha
For values near 0, use Math.expm1(x) instead of Math.exp(x) - 1 — the naive subtraction loses precision.
Related
Math.log
Returns the natural logarithm (base e, or ln) of a number. Inverse of Math.exp.
Math.expm1
Returns e^x - 1, computed accurately even for very small x. Introduced in ES2015 to avoid catastrophic cancellation near zero.
Math.pow
Returns base raised to the power of exponent. In modern code the `**` operator (ES2016) is usually preferred for readability and identical semantics.
Math.log2
Returns the base-2 logarithm of a number. Introduced in ES2015 and useful for information theory, tree depths, and bit counts.
Math.log10
Returns the base-10 logarithm of a number. Introduced in ES2015 for accurate common-log calculations (decibels, pH, orders of magnitude).