expm1
result = expm1(x)
Input: x · Output: result
What it is
e^x - 1, computed so it stays accurate for x near zero (expm1(1e-15) does not lose precision to the cancellation that exp(x) - 1 would hit there). x is a scalar, Vec, or Mat/Signal.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = expm1(x) | x scalar, Vec, Mat, or Signalnot documented yet | result — | Returns exactly the same type and shape as x. |
Examples
No documentation example calls this form yet. The Core maths chapter is where one belongs.
How it works
expm1(x) = e^x - 1, log1p(x) = ln(1+x): the entire point of both is numerical accuracy near zero, where the naive exp(x) - 1 / ln(1 + x) loses precision to catastrophic cancellation (exp(1e-15) - 1 rounds to a value with only a couple of correct digits; f64::exp_m1/f64::ln_1p do not). Using the naive formula here would defeat the reason these functions exist -- see the expm1_is_accurate_near_zero/ log1p_is_accurate_near_zero tests below, which fail under the naive formula and pass under exp_m1/ln_1p.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.