CoreModules.Math) provides comprehensive mathematical functions and constants, wrapping .NET’s System.Math class.
Constants
math.pi
The value of π (pi).math.huge
Represents positive infinity.Basic Functions
math.abs(x)
Returns the absolute value.math.ceil(x)
Rounds up to the nearest integer.math.floor(x)
Rounds down to the nearest integer.math.max(…)
Returns the maximum value from arguments.math.min(…)
Returns the minimum value from arguments.Rounding and Decomposition
math.modf(x)
Returns the integer and fractional parts of a number.math.fmod(x, y)
Returns the remainder of division.Power and Exponential
math.pow(x, y)
Raises x to the power of y.^ operator:
math.sqrt(x)
Returns the square root.math.exp(x)
Returns e raised to the power of x.math.log(x [, base])
Returns the logarithm of x.x- Valuebase- Optional base (default: e for natural logarithm)
math.frexp(x)
Decomposes a number into mantissa and exponent.x = m * 2^e, where 0.5 <= |m| < 1
math.ldexp(m, e)
Computesm * 2^e.
Trigonometric Functions
math.sin(x) / math.cos(x) / math.tan(x)
Basic trigonometric functions (x in radians).math.asin(x) / math.acos(x) / math.atan(x)
Inverse trigonometric functions (return radians).asin and acos require -1 ≤ x ≤ 1
math.atan2(y, x)
Returns the angle (in radians) from the x-axis to the point (x, y).math.sinh(x) / math.cosh(x) / math.tanh(x)
Hyperbolic trigonometric functions.Angle Conversion
math.deg(x)
Converts radians to degrees.math.rad(x)
Converts degrees to radians.Random Numbers
math.random([m [, n]])
Generates random numbers.math.random()- Returns float in [0, 1)math.random(m)- Returns integer in [1, m]math.random(m, n)- Returns integer in [min(m,n), max(m,n)]
math.randomseed(x)
Sets the random number generator seed.System.Random class internally, initialized per script instance.