math¶
A library of math functions.
Nova note: Includes modern helpers such as math.round, math.clamp, and math.log(x, base).
Description¶
This library is an interface to the standard C math library, providing all of its functions inside the math table.
Properties¶
e Supported The value of Euler's number, e.
The value of Euler's number, e.
huge Supported Returns a value larger than or equal to any other numerical value (about 21024).
Returns a value larger than or equal to any other numerical value (about 21024). Dividing a positive number by zero yields this same value.
nan Supported A NaN value, as defined by the IEEE 754 standard.
A NaN value, as defined by the IEEE 754 standard. Comparing directly to
math.nan will always return false; use math.isnan() instead.
phi Supported The value of the golden ratio.
The value of the golden ratio.
pi Supported The value of pi.
The value of pi.
sqrt2 Supported The value of the square root of 2.
The value of the square root of 2.
tau Supported The value of tau, which is defined as 2 * math.pi.
The value of tau, which is defined as 2 * math.pi.
Functions¶
abs Supported Returns the absolute value of x.
Returns the absolute value of x.
acos Supported Returns the arc cosine of x.
Returns the arc cosine of x.
asin Supported Returns the arc sine of x.
Returns the arc sine of x.
atan Supported Returns the arc tangent of x in radians.
Returns the arc tangent of x in radians.
atan2 Supported Returns the arc tangent of y/x (in radians) while using the signs of both parameters to find the quadrant of the result.
Returns the arc tangent of y/x (in radians) while using the signs of
both parameters to find the quadrant of the result. It also handles
correctly the case of x being zero.
ceil Supported Returns the smallest integer larger than or equal to x.
Returns the smallest integer larger than or equal to x.
clamp Supported Returns a number between min and max, inclusive.
Returns a number between min and max, inclusive.
cos Supported Returns the cosine of x, assumed to be in radians.
Returns the cosine of x, assumed to be in radians.
cosh Supported Returns the hyperbolic cosine of x.
Returns the hyperbolic cosine of x.
deg Supported Returns the angle x (given in radians) in degrees.
Returns the angle x (given in radians) in degrees.
exp Supported Returns the value e^x.
Returns the value e^x.
floor Supported Returns the largest integer smaller than or equal to x.
Returns the largest integer smaller than or equal to x.
fmod Supported Returns the remainder of the division of x by y that rounds the quotient towards zero.
Returns the remainder of the division of x by y that rounds the
quotient towards zero.
frexp Supported Returns m and e such that x = m\*2^e.
Returns m and e such that x = m*2^e. e is an integer and
the absolute value of m is in the range of 0.5 to 1 (inclusive of
0.5 but exclusive of 1), or zero when x is zero.
isfinite Supported Returns true if x is a finite number.
Returns true if x is a finite number.
Returns true if x is a finite number, meaning it is neither NaN nor
positive or negative infinity (±math.huge).
isinf Supported Returns true if x is positive or negative infinity and false otherwise.
Returns true if x is positive or negative infinity and false otherwise.
Returns true if x is positive or negative infinity
(±math.huge) and false otherwise.
isnan Supported Returns true if x is not a number (NaN) and false otherwise.
Returns true if x is not a number (NaN) and false otherwise.
ldexp Supported Returns x\*2^e (e should be an integer).
Returns x*2^e (e should be an integer).
lerp Supported Returns the linear interpolation between a and b.
Returns the linear interpolation between a and b.
Returns the linear interpolation between a and b based on the factor
t.
This function uses the formula a+(b-a)*t. t is typically between
0 and 1 but values outside this range are acceptable.
log Supported Returns the logarithm of x using the given base.
Returns the logarithm of x using the given base.
Returns the logarithm of x using the given base, or the mathematical
constant e if no base is provided (natural logarithm).
log10 Supported Returns the base-10 logarithm of x.
Returns the base-10 logarithm of x.
map Supported Returns the value of x mapped from one range to another.
Returns the value of x mapped from one range to another.
Returns a value that represents x mapped linearly from the input range
(inmin to inmax) to the output range (outmin to outmax). This is
achieved by determining the relative position of x within the input
range and applying that ratio to the output range.
max Supported Returns the maximum value among the numbers passed to the function.
Returns the maximum value among the numbers passed to the function.
min Supported Returns the minimum value among the numbers passed to the function.
Returns the minimum value among the numbers passed to the function.
modf Supported Returns two numbers: the integral part of x and the fractional part of x.
Returns two numbers: the integral part of x and the fractional part of
x.
noise Supported Returns a Perlin noise value.
Returns a Perlin noise value. The returned value is most often between the
range of -1 to 1 (inclusive) but sometimes may be outside that range;
if the interval is critical to you, use Library.math.clamp(noise, -1, 1)
on the output.
If you leave arguments out, they will be interpreted as zero, so
math.noise(1.158) is equivalent to
Library.math.noise(1.158, 0, 0) and Library.math.noise(1.158, 5.723)
is equivalent to Library.math.noise(1.158, 5.723, 0).
Note that this function uses a Perlin noise algorithm to assign fixed
values to coordinates. For example, Library.math.noise(1.158, 5.723)
will always return 0.48397532105446 and Library.math.noise(1.158, 6)
will always return 0.15315161645412.
If x, y, and z are all integers, the return value will be 0. For
fractional values of x, y, and z, the return value will gradually
fluctuate between -0.5 and 0.5. For coordinates that are close to each
other, the return values will also be close to each other.
The noise repeats with a period of 256 on each axis, so
Library.math.noise(x, y, z) and Library.math.noise(x + 256, y, z)
return identical values.
pow Supported Returns x^y.
Returns x^y.
Returns x^y (you can also use the expression x^y to compute this
value).
rad Supported Returns the angle x (given in degrees) in radians.
Returns the angle x (given in degrees) in radians.
random Supported Returns a random number within the range provided.
Returns a random number within the range provided.
When called without arguments, returns a uniform pseudo-random real number
in the range of 0 to 1 (inclusive of 0 but exclusive of 1).
When called with an integer number m, returns a uniform pseudo-random
integer in the range of 1 to m, inclusive.
When called with two integer numbers m and n, returns a uniform
pseudo-random integer in the range of m to n, inclusive.
Internally, this uses a 32-bit PCG (Permuted Congruential Generator) which achieves excellent statistical performance and makes its output hard to predict.
randomseed Supported Sets x as the seed for the pseudo-random generator.
Sets x as the seed for the pseudo-random generator.
Sets x as the seed for the pseudo-random generator: equal seeds produce
equal sequences of numbers.
round Supported Returns the integer with the smallest difference between it and the given number.
Returns the integer with the smallest difference between it and the given
number. For example, the value 5.8 returns 6.
For values like 0.5 that are equidistant to two integers, the value with
the greater difference between it and zero is chosen. In other words, the
function "rounds away from zero" such that 0.5 rounds to 1 and -0.5
rounds to -1.
sign Supported Returns -1 if x is less than 0, 0 if x equals 0, or 1 if x is greater than 0.
Returns -1 if x is less than 0, 0 if x equals 0, or 1 if x
is greater than 0.
sin Supported Returns the sine of x, assumed to be in radians.
Returns the sine of x, assumed to be in radians.
sinh Supported Returns the hyperbolic sine of x.
Returns the hyperbolic sine of x.
sqrt Supported Returns the square root of x.
Returns the square root of x. You can also use the expression x^0.5
to compute this value.
tan Supported Returns the tangent of x, assumed to be in radians.
Returns the tangent of x, assumed to be in radians.
tanh Supported Returns the hyperbolic tangent of x.
Returns the hyperbolic tangent of x.
Roblox reference: math