Skip to content

math

import math
FunctionSignatureDescription
min(Int, Int) -> IntReturn the smaller of two integers.
max(Int, Int) -> IntReturn the larger of two integers.
abs(Int) -> IntReturn the absolute value of an integer.
pow(Int, Int) -> IntRaise an integer base to an integer exponent.
pi() -> FloatReturn the mathematical constant pi (3.14159…).
e() -> FloatReturn Euler’s number e (2.71828…).
sin(Float) -> FloatReturn the sine of an angle in radians.
cos(Float) -> FloatReturn the cosine of an angle in radians.
tan(Float) -> FloatReturn the tangent of an angle in radians.
log(Float) -> FloatReturn the natural logarithm (base e) of a float.
exp(Float) -> FloatReturn e raised to the given power.
sqrt(Float) -> FloatReturn the square root of a float.
log10(Float) -> FloatReturn the base-10 logarithm of a float.
log2(Float) -> FloatReturn the base-2 logarithm of a float.
sign(Int) -> IntReturn the sign of an integer: -1, 0, or 1.
fmin(Float, Float) -> FloatReturn the smaller of two floats.
fmax(Float, Float) -> FloatReturn the larger of two floats.
fpow(Float, Float) -> FloatRaise a float base to a float exponent.
factorial(Int) -> IntReturn the factorial of a non-negative integer.
choose(Int, Int) -> IntReturn the binomial coefficient C(n, k) = n! / (k! * (n-k)!).
log_gamma(Float) -> FloatReturn the natural logarithm of the gamma function at x.

Return the smaller of two integers.

math.min(3, 7) // => 3

Return the larger of two integers.

math.max(3, 7) // => 7

Return the absolute value of an integer.

math.abs(-5) // => 5

Raise an integer base to an integer exponent.

math.pow(2, 10) // => 1024

Return the mathematical constant pi (3.14159…).

math.pi() // => 3.141592653589793

Return Euler’s number e (2.71828…).

math.e() // => 2.718281828459045

Return the sine of an angle in radians.

math.sin(0.0) // => 0.0

Return the cosine of an angle in radians.

math.cos(0.0) // => 1.0

Return the tangent of an angle in radians.

math.tan(0.0) // => 0.0

Return the natural logarithm (base e) of a float.

math.log(1.0) // => 0.0

Return e raised to the given power.

math.exp(1.0) // => 2.718281828459045

Return the square root of a float.

math.sqrt(16.0) // => 4.0

Return the base-10 logarithm of a float.

math.log10(100.0) // => 2.0

Return the base-2 logarithm of a float.

math.log2(8.0) // => 3.0

Return the sign of an integer: -1, 0, or 1.

math.sign(-42) // => -1

Return the smaller of two floats.

math.fmin(1.5, 2.5) // => 1.5

Return the larger of two floats.

math.fmax(1.5, 2.5) // => 2.5

math.fpow(base: Float, exp: Float) -> Float

Section titled “math.fpow(base: Float, exp: Float) -> Float”

Raise a float base to a float exponent.

math.fpow(2.0, 0.5) // => 1.4142135623730951

Return the factorial of a non-negative integer.

math.factorial(5) // => 120

Return the binomial coefficient C(n, k) = n! / (k! * (n-k)!).

math.choose(5, 2) // => 10

Return the natural logarithm of the gamma function at x.

math.log_gamma(5.0) // => 3.178...