Skip to content

std.math - ZZ

Numerics: rounding, roots/powers, trig, predicates, number theory, statistics, linear algebra, constants. Pure-ZZ integer implementations plus native float overloads. Bit-identical on VM and AOT (-fwrapv + no -ffast-math).

import std.math

std.math is the numeric workhorse. Constants (PI, E, TAU, …) are true Float values — the checker resolves them without (); calling one is an error. Functions are generic over int|float where applicable.

import std.math
math.abs(-5) // 5
math.floor(3.7) // 3
math.ceil(3.2) // 4
math.sqrt(9.0) // 3.0
math.pow(2, 10) // 1024.0
x := math.random() // 0.0 <= x < 1.0
math.PI // 3.1415926... (constant, no parens)
  • isqrt/factorial return Result<int, str> — error on negative input.
  • mean/median return Result<float, str> — error on empty input.
  • min/max work for int, float, str (anything comparable).
  • rand_range is generic over T returning float.
  • Constants — calling math.PI() is an error; use math.PI directly.
  • Bit-identical on VM and AOT (-fwrapv + no -ffast-math).
  • Kahan-compensated sum_f/mean_f for float precision.
  • Pure-ZZ integer implementations shadow natives at type-check time.

73 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.

Function Signature Description
std.math.E E() -> float —
std.math.E E(value = 2.718281828459045) -> float —
std.math.INF INF() -> float —
std.math.INF INF(value = inf) -> float —
std.math.LN_10 LN_10() -> float —
std.math.LN_10 LN_10(value = 2.302585092994046) -> float —
std.math.LN_2 LN_2() -> float —
std.math.LN_2 LN_2(value = 0.6931471805599453) -> float —
std.math.LOG10_E LOG10_E() -> float —
std.math.LOG10_E LOG10_E(value = 0.4342944819032518) -> float —
std.math.LOG2_E LOG2_E() -> float —
std.math.LOG2_E LOG2_E(value = 1.4426950408889634) -> float —
std.math.NAN NAN() -> float —
std.math.NAN NAN(value = NaN) -> float —
std.math.PI PI() -> float —
std.math.PI PI(value = 3.141592653589793) -> float —
std.math.SQRT_1_2 SQRT_1_2() -> float —
std.math.SQRT_1_2 SQRT_1_2(value = 0.7071067811865476) -> float —
std.math.SQRT_2 SQRT_2() -> float —
std.math.SQRT_2 SQRT_2(value = 1.4142135623730951) -> float —
std.math.TAU TAU() -> float —
std.math.TAU TAU(value = 6.283185307179586) -> float —
std.math.abs abs<T>(v: T) -> T Absolute value
std.math.acos acos<T>(x: T) -> float Arccosine
std.math.asin asin<T>(x: T) -> float Arcsine
std.math.atan atan<T>(x: T) -> float Arctangent
std.math.ceil ceil(v: float) -> int Ceil to int
std.math.clamp clamp<T>(val: T, min: T, max: T) -> float Clamp to range
std.math.cos cos<T>(x: T) -> float Cosine
std.math.cos_deg cos_deg<T>(x: T) -> float Cosine (degrees)
std.math.count count(arr: [int], target: int) -> int Occurrences
std.math.dot_product dot_product(v1: [float], v2: [float]) -> Result<float, str> Dot product
std.math.exp exp<T>(x: T) -> float e^x
std.math.factorial factorial(n: int) -> Result<int, str> Factorial
std.math.floor floor(v: float) -> int Floor to int
std.math.gcd gcd(a: int, b: int) -> int GCD
std.math.hypot hypot<T>(x: T, y: T) -> float Hypotenuse
std.math.is_even is_even(n: int) -> bool Even check
std.math.is_inf is_inf<T>(x: T) -> bool Infinity check
std.math.is_nan is_nan<T>(x: T) -> bool NaN check
std.math.is_odd is_odd(n: int) -> bool Odd check
std.math.isqrt isqrt(n: int) -> Result<int, str> Integer sqrt
std.math.lcm lcm(a: int, b: int) -> int LCM
std.math.log log<T>(x: T) -> float Natural log
std.math.log10 log10<T>(x: T) -> float Base-10 log
std.math.magnitude magnitude(v: [float]) -> float Vector magnitude
std.math.matrix_mul matrix_mul(m1: [[float]], m2: [[float]]) -> Result<[[float]], str> Matrix multiply
std.math.max max<T>(a: T, b: T) -> T Max
std.math.max_arr max_arr<T>(arr: [T]) -> Option<T> Max array
std.math.mean mean(list: [float]) -> Result<float, str> Mean
std.math.mean_f mean_f(arr: [float]) -> Result<float, str> Mean
std.math.median median(list: [float]) -> Result<float, str> Median
std.math.median_f median_f(arr: [float]) -> Result<float, str> Median
std.math.min min<T>(a: T, b: T) -> T Min
std.math.min_arr min_arr<T>(arr: [T]) -> Option<T> Min array
std.math.pow pow<T>(base: T, exp: T) -> float Power
std.math.product product(arr: [int]) -> int Product ints
std.math.product_f product_f(arr: [float]) -> float Float product
std.math.rand_range rand_range<T>(min: T, max: T) -> float Random in range
std.math.random random() -> float Random [0, 1)
std.math.root root<T>(x: T, n: T) -> float n-th root
std.math.round round<T>(x: T) -> float Round
std.math.signum signum<T>(x: T) -> T Sign (-1/0/1)
std.math.sin sin<T>(x: T) -> float Sine (radians)
std.math.sin_deg sin_deg<T>(x: T) -> float Sine (degrees)
std.math.sqrt sqrt<T>(v: T) -> float Square root
std.math.sum sum(arr: [int]) -> int Sum ints
std.math.sum_f sum_f(arr: [float]) -> float Kahan float sum
std.math.tan tan<T>(x: T) -> float Tangent
std.math.tan_deg tan_deg<T>(x: T) -> float Tangent (degrees)
std.math.to_degrees to_degrees<T>(rad: T) -> float Rad → deg
std.math.to_radians to_radians<T>(deg: T) -> float Deg → rad
std.math.trunc trunc<T>(x: T) -> float Truncate
  • std.time — Clocks, sleeps, durations and RFC 3339 calendar dates.

Full index: API reference · Standard library