math module

Floating-point math. Trig, exponentials, rounding, min/max/clamp, and a couple of list aggregations (sum, mean, product).

import "math" as math;

print(math.sqrt(2));         // 1.4142...
print(math.pi);              // 3.1415926...
print(math.clamp(150, 0, 100));   // 100
print(math.sum([1, 2, 3]));  // 6

Powers & exponentials

FunctionDescription
math.sqrt(x), math.pow(x, y)
math.exp(x)e^x
math.log(x), math.log2(x), math.log10(x)

Trig

FunctionDescription
math.sin(x), math.cos(x), math.tan(x)Argument in radians.
math.asin(x), math.acos(x), math.atan(x), math.atan2(y, x)
math.to_radians(deg), math.to_degrees(rad)

Rounding & abs

FunctionDescription
math.floor(x), math.ceil(x), math.round(x), math.trunc(x)
math.abs(x)Absolute value.
math.sign(x)-1, 0, or 1.

min / max / clamp / lerp

FunctionDescription
math.min(a, b), math.max(a, b)
math.clamp(x, lo, hi)
math.lerp(a, b, t)Linear interpolation.
math.mod(a, b)Non-negative modulo (% follows sign of a).

List aggregations

FunctionDescription
math.sum(xs), math.product(xs), math.mean(xs)

Predicates & constants

ItemDescription
math.is_nan(x), math.is_finite(x)
math.pi, math.eConstants.