Math API
Mathematical functions wrapping the C standard library. All functions accept and return numbers.
Rounding & Truncation
Returns the absolute value.
abs(-5) // 5 abs(3.14) // 3.14
Rounds down toward negative infinity.
floor(3.7) // 3 floor(-1.2) // -2
Rounds up toward positive infinity.
ceil(3.2) // 4 ceil(-1.7) // -1
Rounds to the nearest integer. Halfway values round away from zero.
round(3.5) // 4 round(-1.5) // -2
Truncates toward zero (removes fractional part).
trunc(3.9) // 3 trunc(-3.9) // -3
Returns the sign: -1, 0, or 1.
sign(42) // 1 sign(-7) // -1 sign(0) // 0
Powers & Roots
Returns the square root.
sqrt(16) // 4 sqrt(2) // 1.41421...
Returns the cube root.
cbrt(27) // 3 cbrt(-8) // -2
Returns base raised to the power of exponent.
pow(2, 10) // 1024 pow(25, 0.5) // 5
Exponential & Logarithmic
Returns e raised to the power of value.
Returns 2 raised to the power of value.
Returns exp(value) - 1 with better precision for small values.
Returns the natural logarithm (base e).
Returns the base-10 logarithm.
log10(100) // 2 log10(1000) // 3
Returns the base-2 logarithm.
log2(8) // 3 log2(1024) // 10
Returns log(1 + value) with better precision for small values.
Trigonometric
All trigonometric functions use radians.
Returns the sine, cosine, or tangent.
sin(0) // 0 cos(0) // 1 tan(3.14159265 / 4) // ~1
Inverse trigonometric functions. Returns radians.
Returns the arc tangent of y/x using both signs to determine the quadrant. Result is in (-π, π].
atan2(1, 1) // ~0.7854 (π/4) atan2(0, -1) // ~3.14159 (π)
Hyperbolic
Hyperbolic sine, cosine, and tangent.
Inverse hyperbolic functions.
Min / Max / Clamp
Returns the smaller of two numbers.
Returns the larger of two numbers.
Clamps a value to the range [minVal, maxVal].
clamp(5, 0, 10) // 5 clamp(-3, 0, 10) // 0 clamp(15, 0, 10) // 10
Modulo & Remainder
Floating-point remainder of x / y (same sign as x).
fmod(5.5, 2) // 1.5 fmod(-5.5, 2) // -1.5
IEEE remainder of x / y (rounds quotient to nearest integer).
Utility
Returns sqrt(x² + y²) computed without overflow.
hypot(3, 4) // 5 hypot(5, 12) // 13
Converts degrees to radians.
toRadians(180) // ~3.14159 (π) toRadians(90) // ~1.5708 (π/2)
Converts radians to degrees.
toDegrees(3.14159265) // ~180
Interpolation & Mapping
Linearly interpolates between start and end by factor t.
lerp(0, 100, 0.5) // 50 lerp(0, 100, 0.25) // 25
Re-maps a value from one range to another.
map(5, 0, 10, 0, 100) // 50 map(0.5, 0, 1, -1, 1) // 0
Type Checks
Checks if a number is NaN.
Checks if a number is positive or negative infinity.
Checks if a number is finite (not NaN and not infinite).
isFinite(42) // true isFinite(1 / 0) // false
See also: Conversions API — List API — String API