Math functions

Arithmetic, rounding, roots, logs, and trigonometry.

FunctionDescription
abs(x: f64) → f64Absolute value.
acos(x: number) → f64Arccosine, in radians, of a value in [-1, 1].
asin(x: number) → f64Arcsine, in radians, of a value in [-1, 1].
atan(x: number) → f64Arctangent, in radians.
atan2(a: number, b: number) → f64Arctangent of a/b in radians, using the signs of both to pick the quadrant.
cbrt(x: f64) → f64Cube root.
ceil(x: f64) → f64Round up to the nearest integer.
clamp(x: number, lo: number, hi: number) → f64Constrain x to the range [lo, hi].
cos(x: f64) → f64Cosine of an angle in radians.
degrees(x: number) → f64Convert an angle from radians to degrees.
e() → f64Euler's number e (≈ 2.71828).
exp(x: f64) → f64e raised to the power x.
floor(x: f64) → f64Round down to the nearest integer.
hypot(a: f64, b: f64) → f64Length of the hypotenuse sqrt(a² + b²).
ln(x: f64) → f64Natural (base-e) logarithm.
log10(x: f64) → f64Base-10 logarithm.
log2(x: f64) → f64Base-2 logarithm.
max(a: f64, b: f64) → f64The larger of two numbers.
min(a: f64, b: f64) → f64The smaller of two numbers.
pi() → f64The constant π (≈ 3.14159).
pow(a: f64, b: f64) → f64Raise a to the power b.
radians(x: number) → f64Convert an angle from degrees to radians.
round(x: f64) → f64Round to the nearest integer (ties away from zero).
sign(x: f64) → f64The sign of x: 1, -1, or 0.
sin(x: f64) → f64Sine of an angle in radians.
sqrt(x: f64) → f64Square root.
tan(x: f64) → f64Tangent of an angle in radians.
tau() → f64The constant τ = 2π (≈ 6.28319).
trunc(x: f64) → f64Discard the fractional part, rounding toward zero.