Math
Lua math functions and Orion Solutions math helpers.
The math library provides the standard Lua/LuaJIT mathematical functions and Orion Solutions-specific helpers.
abs
math.abs(x: number): numberReturns the absolute value of x.
acos
math.acos(x: number): numberReturns the arc cosine of x in radians.
asin
math.asin(x: number): numberReturns the arc sine of x in radians.
atan
math.atan(x: number): numberReturns the arc tangent of x in radians.
atan2
math.atan2(y: number, x: number): numberReturns the arc tangent of y / x while using the signs of both values to determine the result quadrant.
ceil
math.ceil(x: number): numberReturns the smallest integer greater than or equal to x.
clamp
math.clamp(value: number, min: number, max: number): numbernumberValue to clamp.numberMinimum value.numberMaximum value.Returns value clamped between min and max. Reversed limits are handled automatically.
cos
math.cos(x: number): numberReturns the cosine of x in radians.
cosh
math.cosh(x: number): numberReturns the hyperbolic cosine of x.
deg
math.deg(x: number): numberConverts an angle from radians to degrees.
exp
math.exp(x: number): numberReturns e raised to the power of x.
floor
math.floor(x: number): numberReturns the largest integer less than or equal to x.
fmod
math.fmod(x: number, y: number): numberReturns the remainder of x / y with the quotient rounded toward zero.
frexp
math.frexp(x: number): number, numberReturns m and e such that x = m * 2^e.
huge
math.huge: numberA numeric value greater than or equal to any other finite numerical value.
ldexp
math.ldexp(m: number, e: number): numberReturns m * 2^e.
log
math.log(x: number): numberReturns the natural logarithm of x.
log10
math.log10(x: number): numberReturns the base-10 logarithm of x.
map
math.map(value: number, in_from: number, in_to: number, out_from: number, out_to: number[, should_clamp: boolean]): numbernumberValue to map.numberInput range minimum.numberInput range maximum.numberOutput range minimum.numberOutput range maximum.booleanOptionally clamps the mapped percentage to the input range.Linearly maps a value from one numeric range into another.
max
math.max(x: number[, ...]): numberReturns the maximum value among its arguments.
min
math.min(x: number[, ...]): numberReturns the minimum value among its arguments.
modf
math.modf(x: number): number, numberReturns the integral and fractional parts of x.
normalize_yaw
math.normalize_yaw(x: number): numberNormalizes a yaw angle into the range [-180, 180).
pi
math.pi: numberThe value of pi.
pow
math.pow(x: number, y: number): numberReturns x raised to the power of y.
rad
math.rad(x: number): numberConverts an angle from degrees to radians.
random
math.random([m[, n]]): numberReturns a pseudo-random number. With no arguments it returns a value in [0, 1); with one or two integer arguments it returns an integer in the requested range.
randomseed
math.randomseed(x: number)Sets the seed used by the pseudo-random number generator.
sin
math.sin(x: number): numberReturns the sine of x in radians.
sinh
math.sinh(x: number): numberReturns the hyperbolic sine of x.
sqrt
math.sqrt(x: number): numberReturns the square root of x.
tan
math.tan(x: number): numberReturns the tangent of x in radians.
tanh
math.tanh(x: number): numberReturns the hyperbolic tangent of x.
Examples
print(math.abs(-25))
print(math.clamp(150, 0, 100))
print(math.map(50, 0, 100, 0, 1))
print(math.map(150, 0, 100, 0, 1, true))
print(math.normalize_yaw(270))
print(math.rad(180))
print(math.deg(math.pi))