Reference · Math

math.cbrt

signature
math.cbrt(num) -> float

What it does

The cube root of a number, as a float, as Python's math.cbrt. A negative number has a negative cube root, so unlike math.sqrt and math.pow it takes any number.

Examples

print(math.cbrt(27), math.cbrt(-8), math.cbrt(2))print(math.cbrt(0.001), math.cbrt(1e30))
output
3.0 -2.0 1.25992104989487320.1 10000000000.0

Edge cases

print(math.cbrt(-27) == -3, math.cbrt(0))print(math.cbrt(-math.inf), math.cbrt(math.nan))print(math.cbrt(-8), math.pow(8, 1/3))
output
true 0.0-inf NaN-2.0 2.0

Errors

There is no domain error: every number has a cube root. A value that is not a number is a runtime error, not an error value; a decimal is converted first with float.

this one fails
print(math.cbrt("8"))
output
line 1: `math.cbrt` expects a number as argument 1, got str
this one fails
print(math.pow(-8, 1/3))
output
line 1: `math.pow`: math domain error (-8, 0.3333333333333333)

Chaining

print(2 * 2 * 2 | math.cbrt)print([1, 8, 27] | map(math.cbrt))
output
2.0[1.0, 2.0, 3.0]

See also

math.sqrt, math.pow, pow, math.exp

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

Thread 0 posts

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