Math
The Math namespace contains functions that are available both in the global scope and in the Math
namespace.
Some of the math functions can be used in a postfix style which can make the code more readable.
T 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
abs(T) -> T
Return the absolute value, where T is a numeric type.
ceil(float) -> int
Returns the value rounded up to the nearest integer.
floor(float) -> int
Returns the value rounded down to the nearest integer.
round(float) -> int
Return the value rounded to the nearest integer
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
Return the log of the first value with a base of the second value
min(T, T) -> T
max(T, T) -> T
Return the arguments with the minimum (or maximum) value. All arguments must be of the same numeric type.
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
Square root
pow(float, float) -> float
Return the value of the first value raised to the second
Trigonometric Functions
acos(float) -> angle
Returns the arccosine, or inverse cosine, of a number. The arccosine is the angle whose cosine is number.
asin(float) -> angle
Returns the arcsine, or inverse sine, of a number. The arcsine is the angle whose sine is number.
atan(float) -> angle
Returns the arctangent, or inverse tangent, of a number.
atan2(float, float) -> angle
cos(angle) -> float
sin(angle) -> float
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)
).
© 2024 SixtyFPS GmbH