Reference · Math
math.exp
math.exp(num) -> floatWhat it does
e raised to the power of the number, as a float, as Python's math.exp. It is the
inverse of math.log: math.exp(math.log(x)) is x, give
or take the last digit.
Examples
print(math.exp(0), math.exp(1), math.exp(-1))print(math.exp(10), math.exp(math.log(10)))1.0 2.718281828459045 0.3678794411714423322026.465794806718 10.000000000000002Edge cases
- A large negative number gives
0.0: underflow is not an error. 709is about the largest input that fits a float (about 8.2 × 10³⁰⁷);710is a range error.-infgives0.0,infgivesinf,NaNgivesNaN.- For
math.exp(x) - 1with a tinyx, math.expm1 keeps the digits that the subtraction loses.
print(math.exp(-1000), math.isfinite(math.exp(709)))print(math.exp(-math.inf), math.exp(math.inf), math.exp(math.nan))print(math.exp(1e-10) - 1, math.expm1(1e-10))0.0 true0.0 inf NaN0.0000000001000000082740371 0.000000000100000000005Errors
An input whose result is past the largest float is a runtime error (a range error),
not an error value: it stops the request, and ?? does not catch it. A value that is
not a number is a runtime error too; a decimal is converted first with float.
print(math.exp(710))line 1: `math.exp`: math range error (710)print(math.exp(null))line 1: `math.exp` expects a number as argument 1, got nullChaining
In a pipeline the number comes first. For a whole list, vec.exp does the same in one call:
let rate = 0.05print(rate * 10 | math.exp)print([0, 1, 2] | map(math.exp), vec.exp([0, 1, 2]))1.6487212707001282[1.0, 2.718281828459045, 7.38905609893065] [1.0, 2.718281828459045, 7.38905609893065]See also
math.log, math.expm1, math.exp2, math.pow, vec.exp
Thread 0 posts
On math.exp(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo