Functions
All tyrus:math functions operate on f64 unless noted otherwise and are emitted as direct native calls.
Basics and signs
| Function | Signature | Description |
|---|---|---|
abs | (x: f64) => f64 | Absolute value |
sign | (x: f64) => f64 | Sign (1, -1, or 0) |
sqrt | (x: f64) => f64 | Square root |
cbrt | (x: f64) => f64 | Cube root |
Rounding
| Function | Signature | Description |
|---|---|---|
floor | (x: f64) => f64 | Round down |
ceil | (x: f64) => f64 | Round up |
trunc | (x: f64) => f64 | Truncate toward zero |
round | (x: f64) => f64 | Round to nearest integer |
roundTo | (x: f64, decimals: i32) => f64 | Round to N decimal places |
Trigonometry
| Function | Signature | Description |
|---|---|---|
sin | (x: f64) => f64 | Sine |
cos | (x: f64) => f64 | Cosine |
tan | (x: f64) => f64 | Tangent |
asin | (x: f64) => f64 | Arc sine |
acos | (x: f64) => f64 | Arc cosine |
atan | (x: f64) => f64 | Arc tangent |
atan2 | (y: f64, x: f64) => f64 | Arc tangent of y/x |
degToRad | (degrees: f64) => f64 | Convert degrees to radians |
radToDeg | (radians: f64) => f64 | Convert radians to degrees |
Hyperbolic
| Function | Signature | Description |
|---|---|---|
sinh | (x: f64) => f64 | Hyperbolic sine |
cosh | (x: f64) => f64 | Hyperbolic cosine |
tanh | (x: f64) => f64 | Hyperbolic tangent |
Exponentials and logarithms
| Function | Signature | Description |
|---|---|---|
exp | (x: f64) => f64 | e^x |
log | (x: f64) => f64 | Natural logarithm |
log10 | (x: f64) => f64 | Base-10 logarithm |
log2 | (x: f64) => f64 | Base-2 logarithm |
pow | (base: f64, exp: f64) => f64 | Power |
Selection and low-level
| Function | Signature | Description |
|---|---|---|
max | (a: f64, b: f64) => f64 | Maximum |
min | (a: f64, b: f64) => f64 | Minimum |
clamp | (value: f64, min: f64, max: f64) => f64 | Clamp value to range |
clampMin | (value: f64, min: f64) => f64 | Enforce minimum |
clampMax | (value: f64, max: f64) => f64 | Enforce maximum |
imul | (a: i32, b: i32) => i32 | C-style 32-bit multiplication |
clz32 | (x: i32) => i32 | Count leading zeros in 32-bit integer |
Advanced utilities
| Function | Signature | Description |
|---|---|---|
approxEqual | (a: f64, b: f64, tolerance?: f64) => boolean | Compare floats within tolerance |
lerp | (start: f64, end: f64, amount: f64) => f64 | Linear interpolation |
inverseLerp | (start: f64, end: f64, value: f64) => f64 | Inverse linear interpolation |
remap | (value: f64, inMin: f64, inMax: f64, outMin: f64, outMax: f64) => f64 | Remap value between ranges |
smoothstep | (edge0: f64, edge1: f64, x: f64) => f64 | Smooth Hermite interpolation |
gcd | (a: u32, b: u32) => u32 | Greatest common divisor |
lcm | (a: u32, b: u32) => u32 | Least common multiple |
randomRange | (min: f64, max: f64) => f64 | Random float in half-open interval |
Statistics and combinatorics
| Function | Signature | Description |
|---|---|---|
mean | (values: f64[]) => f64 | Arithmetic mean; 0.0 for empty array |
median | (values: f64[]) => f64 | Median; 0.0 for empty array |
mode | (values: f64[]) => f64 | Most frequent value; 0.0 for empty array |
variance | (values: f64[]) => f64 | Population variance; 0.0 for empty array |
stdDev | (values: f64[]) => f64 | Population standard deviation; 0.0 for empty array |
percentile | (p: f64, values: f64[]) => f64 | p-th percentile (0-100) with linear interpolation; 0.0 for empty array |
factorial | (n: u128) => u128 | n! |
permutation | (n: u128, k: u128) => u128 | n! / (n - k)! |
combination | (n: u128, k: u128) => u128 | n! / (k! * (n - k)!) |
Number theory
| Function | Signature | Description |
|---|---|---|
isPrime | (n: u64) => boolean | true if n is prime |
nextPrime | (n: u64) => u64 | Smallest prime strictly greater than n |
primeFactors | (n: u64) => u64[] | Prime factors of n |
fibonacci | (n: u64) => u64 | n-th Fibonacci number |
Geometry and numeric utilities
| Function | Signature | Description |
|---|---|---|
hypot | (x: f64, y: f64) => f64 | Euclidean 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) => f64 | Copy sign of y to x |
fmod | (x: f64, y: f64) => f64 | Floating-point remainder of x / y |
logBase | (x: f64, base: f64) => f64 | Logarithm of x with given base |
powi | (x: f64, exp: i32) => f64 | x raised to integer power exp |
