math_ext

.zn module

Integer math, number theory, and statistics over the native math module. import "math_ext".

Integer / number theory

Statistics (over [float])

Interpolation / angles

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.

On this page