Reference · Math

math.exp2

signature
math.exp2(num) -> float

What it does

2 raised to the power of the number, as a float, as Python's math.exp2. The exponent can be fractional or negative. For an int power of two that stays an int, use pow.

Examples

print(math.exp2(10), math.exp2(0.5), math.exp2(-1))print(math.exp2(10), pow(2, 10))
output
1024.0 1.4142135623730951 0.51024.0 1024

Edge cases

print(type_of(math.exp2(10)), type_of(pow(2, 10)))print(math.isfinite(math.exp2(1023)), math.exp2(-2000))print(math.exp2(math.inf), math.exp2(-math.inf), math.exp2(math.nan))
output
float inttrue 0.0inf 0.0 NaN

Errors

A result past the largest float is a runtime error (a range error), not an error value: it stops the request. A value that is not a number is a runtime error too.

this one fails
print(math.exp2(1024))
output
line 1: `math.exp2`: math range error (1024)
this one fails
print(math.exp2("10"))
output
line 1: `math.exp2` expects a number as argument 1, got str

Chaining

print(8 | math.exp2)print([0, 1, 2, 3] | map(math.exp2))print(10 | math.exp2 | math.log2)
output
256.0[1.0, 2.0, 4.0, 8.0]10.0

See also

math.log2, math.exp, math.pow, pow, math.ldexp

Thread
8Useful? Like it, or add to its thread below.

Thread 0 posts

On math.exp2(): 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