Skip to content

Functions ​

All tyrus:math functions operate on f64 unless noted otherwise and are emitted as direct native calls.

Basics and signs ​

FunctionSignatureDescription
abs(x: f64) => f64Absolute value
sign(x: f64) => f64Sign (1, -1, or 0)
sqrt(x: f64) => f64Square root
cbrt(x: f64) => f64Cube root

Rounding ​

FunctionSignatureDescription
floor(x: f64) => f64Round down
ceil(x: f64) => f64Round up
trunc(x: f64) => f64Truncate toward zero
round(x: f64) => f64Round to nearest integer
roundTo(x: f64, decimals: i32) => f64Round to N decimal places

Trigonometry ​

FunctionSignatureDescription
sin(x: f64) => f64Sine
cos(x: f64) => f64Cosine
tan(x: f64) => f64Tangent
asin(x: f64) => f64Arc sine
acos(x: f64) => f64Arc cosine
atan(x: f64) => f64Arc tangent
atan2(y: f64, x: f64) => f64Arc tangent of y/x
degToRad(degrees: f64) => f64Convert degrees to radians
radToDeg(radians: f64) => f64Convert radians to degrees

Hyperbolic ​

FunctionSignatureDescription
sinh(x: f64) => f64Hyperbolic sine
cosh(x: f64) => f64Hyperbolic cosine
tanh(x: f64) => f64Hyperbolic tangent

Exponentials and logarithms ​

FunctionSignatureDescription
exp(x: f64) => f64e^x
log(x: f64) => f64Natural logarithm
log10(x: f64) => f64Base-10 logarithm
log2(x: f64) => f64Base-2 logarithm
pow(base: f64, exp: f64) => f64Power

Selection and low-level ​

FunctionSignatureDescription
max(a: f64, b: f64) => f64Maximum
min(a: f64, b: f64) => f64Minimum
clamp(value: f64, min: f64, max: f64) => f64Clamp value to range
clampMin(value: f64, min: f64) => f64Enforce minimum
clampMax(value: f64, max: f64) => f64Enforce maximum
imul(a: i32, b: i32) => i32C-style 32-bit multiplication
clz32(x: i32) => i32Count leading zeros in 32-bit integer

Advanced utilities ​

FunctionSignatureDescription
approxEqual(a: f64, b: f64, tolerance?: f64) => booleanCompare floats within tolerance
lerp(start: f64, end: f64, amount: f64) => f64Linear interpolation
inverseLerp(start: f64, end: f64, value: f64) => f64Inverse linear interpolation
remap(value: f64, inMin: f64, inMax: f64, outMin: f64, outMax: f64) => f64Remap value between ranges
smoothstep(edge0: f64, edge1: f64, x: f64) => f64Smooth Hermite interpolation
gcd(a: u32, b: u32) => u32Greatest common divisor
lcm(a: u32, b: u32) => u32Least common multiple
randomRange(min: f64, max: f64) => f64Random float in half-open interval

Statistics and combinatorics ​

FunctionSignatureDescription
mean(values: f64[]) => f64Arithmetic mean; 0.0 for empty array
median(values: f64[]) => f64Median; 0.0 for empty array
mode(values: f64[]) => f64Most frequent value; 0.0 for empty array
variance(values: f64[]) => f64Population variance; 0.0 for empty array
stdDev(values: f64[]) => f64Population standard deviation; 0.0 for empty array
percentile(p: f64, values: f64[]) => f64p-th percentile (0-100) with linear interpolation; 0.0 for empty array
factorial(n: u128) => u128n!
permutation(n: u128, k: u128) => u128n! / (n - k)!
combination(n: u128, k: u128) => u128n! / (k! * (n - k)!)

Number theory ​

FunctionSignatureDescription
isPrime(n: u64) => booleantrue if n is prime
nextPrime(n: u64) => u64Smallest prime strictly greater than n
primeFactors(n: u64) => u64[]Prime factors of n
fibonacci(n: u64) => u64n-th Fibonacci number

Geometry and numeric utilities ​

FunctionSignatureDescription
hypot(x: f64, y: f64) => f64Euclidean norm sqrt(x^2 + y^2)
toPolar(x: f64, y: f64) => [f64, f64]Convert Cartesian to polar (r, theta)
toCartesian(r: f64, theta: f64) => [f64, f64]Convert polar to Cartesian (x, y)
copysign(x: f64, y: f64) => f64Copy sign of y to x
fmod(x: f64, y: f64) => f64Floating-point remainder of x / y
logBase(x: f64, base: f64) => f64Logarithm of x with given base
powi(x: f64, exp: i32) => f64x raised to integer power exp