Reference · Math

math.exp

signature
math.exp(num) -> float

What 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)))
output
1.0 2.718281828459045 0.3678794411714423322026.465794806718 10.000000000000002

Edge cases

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))
output
0.0 true0.0 inf NaN0.0000000001000000082740371 0.000000000100000000005

Errors

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.

this one fails
print(math.exp(710))
output
line 1: `math.exp`: math range error (710)
this one fails
print(math.exp(null))
output
line 1: `math.exp` expects a number as argument 1, got null

Chaining

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]))
output
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
7Useful? Like it, or add to its thread below.

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