math

Show Deprecated

This library is an interface to the standard C math library, providing all of its functions inside the math table.

Summary

Functions

Properties

  • Returns a value larger than or equal to any other numerical value (about 21024).

  • The value of pi.

Functions

Returns the absolute value of x.

Parameters

Returns

acos

Returns the arc cosine of x.

Parameters

Returns

asin

Returns the arc sine of x.

Parameters

Returns

atan

Returns the arc tangent of x in radians.

Parameters

Returns

atan2

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.

Parameters

Returns

ceil

Returns the smallest integer larger than or equal to x.

Parameters

Returns

clamp

Returns a number between min and max, inclusive.

Parameters

min: number
max: number

Returns

Returns the cosine of x, assumed to be in radians.

Parameters

Returns

cosh

Returns the hyperbolic cosine of x.

Parameters

Returns

Returns the angle x (given in radians) in degrees.

Parameters

Returns

Returns the value e^x.

Parameters

Returns

floor

Returns the largest integer smaller than or equal to x.

Parameters

Returns

fmod

Returns the remainder of the division of x by y that rounds the quotient towards zero.

Parameters

Returns

frexp

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.

Parameters

ldexp

Returns x*2^e (e should be an integer).

Parameters

Returns

lerp

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.

Parameters

The starting value.

The ending value.

The interpolation factor, typically between 0 and 1.

Returns

The interpolated value between a and b.

Returns the logarithm of x using the given base, or the mathematical constant e if no base is provided (natural logarithm).

Parameters

base: number

The base of the logarithm, the constant e by default.

Default Value: 2.7182818

Returns

log10

Returns the base-10 logarithm of x.

Parameters

Returns

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.

Parameters

The number to be mapped.

inmin: number

The lower bound of the input range.

inmax: number

The upper bound of the input range.

outmin: number

The lower bound of the output range.

outmax: number

The upper bound of the output range.

Returns

The value of x mapped to the output range.

Returns the maximum value among the numbers passed to the function.

Parameters

...: number

Returns

Returns the minimum value among the numbers passed to the function.

Parameters

...: number

Returns

modf

Returns two numbers: the integral part of x and the fractional part of x.

Parameters

noise

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 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 math.noise(1.158, 0, 0) and math.noise(1.158, 5.723) is equivalent to math.noise(1.158, 5.723, 0).

Note that this function uses a Perlin noise algorithm to assign fixed values to coordinates. For example, math.noise(1.158, 5.723) will always return 0.48397532105446 and 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.

Parameters

Default Value: 0
Default Value: 0

Returns

Returns x^y (you can also use the expression x^y to compute this value).

Parameters

Returns

Returns the angle x (given in degrees) in radians.

Parameters

Returns

random

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.

Parameters

Default Value: 0
Default Value: 1

Returns

randomseed

void

Sets x as the seed for the pseudo-random generator: equal seeds produce equal sequences of numbers.

Parameters

Returns

void

round

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.

Parameters

The value to be rounded.

Returns

sign

Returns -1 if x is less than 0, 0 if x equals 0, or 1 if x is greater than 0.

Parameters

Returns

Returns the sine of x, assumed to be in radians.

Parameters

Returns

sinh

Returns the hyperbolic sine of x.

Parameters

Returns

sqrt

Returns the square root of x. You can also use the expression x^0.5 to compute this value.

Parameters

Returns

Returns the tangent of x, assumed to be in radians.

Parameters

Returns

tanh

Returns the hyperbolic tangent of x.

Parameters

Returns

Properties

huge

Returns a value larger than or equal to any other numerical value (about 21024). Dividing a positive number by zero yields this same value.

The value of pi.