math_ext
.zn moduleInteger math, number theory, and statistics over the native math module. import "math_ext".
Integer / number theory
math_ext.gcd(a, b: int) => intmath_ext.lcm(a, b: int) => intmath_ext.ipow(base, exp: int) => intmath_ext.is_prime(n: int) => boolmath_ext.isqrt(n: int) => intmath_ext.fib(n: int) => intmath_ext.factorial(n: int) => intmath_ext.clamp_int(v, lo, hi: int) => int
Statistics (over [float])
math_ext.mean(nums) => floatmath_ext.variance(nums) => floatmath_ext.std_dev(nums) => floatmath_ext.median(nums) => floatmath_ext.sum_f(nums) => floatmath_ext.product_f(nums) => floatmath_ext.min_f(nums) => (float, bool)math_ext.max_f(nums) => (float, bool)
Interpolation / angles
math_ext.lerp(a, b, t: float) => floatmath_ext.remap(v, in_lo, in_hi, out_lo, out_hi: float) => floatmath_ext.smooth_step(edge0, edge1, x: float) => floatmath_ext.deg_to_rad(deg: float) => floatmath_ext.rad_to_deg(rad: float) => float
math_ext.gcd(a, b: int) => int
Greatest common divisor (Euclidean).
math_ext.lcm(a, b: int) => int
Least common multiple.
math_ext.ipow(base, exp: int) => int
Integer power (0 for negative exp).
math_ext.is_prime(n: int) => bool
Primality test.
math_ext.isqrt(n: int) => int
Integer (floor) square root (0 for negative n).
math_ext.fib(n: int) => int
n-th Fibonacci number (iterative).
math_ext.factorial(n: int) => int
Factorial (0 for negative n).
math_ext.clamp_int(v, lo, hi: int) => int
Clamp an int to [lo, hi].
math_ext.mean(nums) => float
Arithmetic mean.
math_ext.variance(nums) => float
Population variance.
math_ext.std_dev(nums) => float
Population standard deviation.
math_ext.median(nums) => float
Median (sorts a copy).
math_ext.sum_f(nums) => float
Sum.
math_ext.product_f(nums) => float
Product.
math_ext.min_f(nums) => (float, bool)
Minimum; bool false if empty.
math_ext.max_f(nums) => (float, bool)
Maximum; bool false if empty.
math_ext.lerp(a, b, t: float) => float
Linear interpolation.
math_ext.remap(v, in_lo, in_hi, out_lo, out_hi: float) => float
Remap v between ranges.
math_ext.smooth_step(edge0, edge1, x: float) => float
Clamped Hermite smoothstep.
math_ext.deg_to_rad(deg: float) => float
Degrees → radians.
math_ext.rad_to_deg(rad: float) => float
Radians → degrees.