Math
The Math namespace contains functions that are available both in the global scope and in the Math namespace.
// Using the Math namespacex: Math.abs(-10); // sets x to 10// Using the functions via global scope. No need for 'Math' prefix.x: abs(-10); // sets x to 10Some of the math functions can be used in a postfix style which can make the code more readable.
// Using the postfix style.x: (-10).abs(); // sets x to 10T type
Many of the math functions can be used with any numeric type such as angle, duration, float, int, length, and percent. These are represented on this page as T.
General Math Functions
Section titled “General Math Functions”abs(T) -> T
Section titled “abs(T) -> T”Return the absolute value, where T is a numeric type.
Math.abs(-10); // returns 10abs(-10px); // returns 10px(-10).abs(); // returns 10ceil(float) -> int
Section titled “ceil(float) -> int”Returns the value rounded up to the nearest integer.
Math.ceil(4); // returns 4Math.ceil(2.3); // returns 3Math.ceil(-1.5); // returns -1floor(float) -> int
Section titled “floor(float) -> int”Returns the value rounded down to the nearest integer.
Math.floor(4); // returns 4Math.floor(2.3); // returns 2Math.floor(-1.5); // returns -2round(float) -> int
Section titled “round(float) -> int”Return the value rounded to the nearest integer
Math.round(4.5); // returns 5Math.round(4.4); // returns 4Math.round(-1.2); // returns -1sign(float) -> float
Section titled “sign(float) -> float”Returns 1 or -1, indicating the sign of the number passed as argument. Returns 1 if the input is 0 or -0.
Math.sign(10); // returns 1Math.sign(-30); // returns -1Math.sign(0); // returns 1clamp(T, T, T) -> T
Section titled “clamp(T, T, T) -> T”Takes a value, minimum and maximum and returns maximum if
value > maximum, minimum if value < minimum, or value in all other cases.
log(float, float) -> float
Section titled “log(float, float) -> float”Return the log of the first value with a base of the second value
ln(float) -> float
Section titled “ln(float) -> float”Return the natural log of the value. Same as log(e, x)
min(T, T) -> T
Section titled “min(T, T) -> T”max(T, T) -> T
Section titled “max(T, T) -> T”Return the arguments with the minimum (or maximum) value. All arguments must be of the same numeric type.
Math.min(1, 2); // returns 1Math.min(2, 1); // returns 1Math.max(1, 2); // returns 2Math.max(2, 1); // returns 2mod(T, T) -> T
Section titled “mod(T, T) -> T”Perform a modulo operation, where T is some numeric type. Returns the remainder of the euclidean division of the arguments. This always returns a positive number between 0 and the absolute value of the second value.
sqrt(float) -> float
Section titled “sqrt(float) -> float”Square root
pow(float, float) -> float
Section titled “pow(float, float) -> float”Return the value of the first value raised to the second
exp(float, float) -> float
Section titled “exp(float, float) -> float”Return the value of the e raised to the x
Trigonometric Functions
Section titled “Trigonometric Functions”acos(float) -> angle
Section titled “acos(float) -> angle”Returns the arccosine, or inverse cosine, of a number. The arccosine is the angle whose cosine is number.
asin(float) -> angle
Section titled “asin(float) -> angle”Returns the arcsine, or inverse sine, of a number. The arcsine is the angle whose sine is number.
atan(float) -> angle
Section titled “atan(float) -> angle”Returns the arctangent, or inverse tangent, of a number.
atan2(float, float) -> angle
Section titled “atan2(float, float) -> angle”cos(angle) -> float
Section titled “cos(angle) -> float”sin(angle) -> float
Section titled “sin(angle) -> float”tan(angle) -> float
Section titled “tan(angle) -> float”The trigonometry function. Note that the should be typed with deg or rad unit
(for example cos(90deg) or sin(slider.value * 1deg)).
© 2025 SixtyFPS GmbH