Skip to content

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

approxEqual() ​

Checks if two floats are equal within an optional tolerance.

SignatureapproxEqual(a: f64, b: f64, tolerance?: f64): boolean
tyrus
const a: f64 = 1.0;
const b: f64 = 1.0000001;
const result: boolean = approxEqual(a, b);
print(result); // true
tyrus
const a: f64 = 1.0;
const b: f64 = 1.1;
const result: boolean = approxEqual(a, b, 0.05);
print(result); // false

lerp() ​

Linearly interpolates between two values.

Signaturelerp(start: f64, end: f64, amount: f64): f64
tyrus
const start: f64 = 0.0;
const end: f64 = 100.0;
const amount: f64 = 0.5;
const result: f64 = lerp(start, end, amount);
print(result); // 50.0

inverseLerp() ​

Returns how far a value is between two endpoints as a normalized fraction.

SignatureinverseLerp(start: f64, end: f64, value: f64): f64
tyrus
const start: f64 = 0.0;
const end: f64 = 100.0;
const value: f64 = 50.0;
const result: f64 = inverseLerp(start, end, value);
print(result); // 0.5

remap() ​

Remaps a value from one range to another.

Signatureremap(value: f64, inMin: f64, inMax: f64, outMin: f64, outMax: f64): f64
tyrus
const value: f64 = 50.0;
const result: f64 = remap(value, 0.0, 100.0, 0.0, 1.0);
print(result); // 0.5

smoothstep() ​

Returns smooth Hermite interpolation between two edges.

Signaturesmoothstep(edge0: f64, edge1: f64, x: f64): f64
tyrus
const result: f64 = smoothstep(0.0, 1.0, 0.5);
print(result); // 0.5

gcd() ​

Returns the greatest common divisor of two unsigned integers.

Signaturegcd(a: u32, b: u32): u32
tyrus
const a: u32 = 12;
const b: u32 = 8;
const result: u32 = gcd(a, b);
print(result); // 4

lcm() ​

Returns the least common multiple of two unsigned integers.

Signaturelcm(a: u32, b: u32): u32
tyrus
const a: u32 = 4;
const b: u32 = 6;
const result: u32 = lcm(a, b);
print(result); // 12

randomRange() ​

Returns a random floating-point number in the half-open interval [min, max).

SignaturerandomRange(min: f64, max: f64): f64
tyrus
const min: f64 = 1.0;
const max: f64 = 10.0;
const result: f64 = randomRange(min, max);
print(result); // A random float in [1.0, 10.0)