math

Jul 13 2018, 12:19 PM PST 2 min

This library is an interface to the standard C math library. The functions are listed below.

Functions

math.abs

number math.abs(number x)

Description: Returns the absolute value of x

math.acos

number math.acos(number x)

Description: Returns the arc cosine of x

math.asin

number math.asin(number x)

Description: Returns the arc sine of x

math.atan

number math.atan(number x)

Description: Returns the arc tangent of x (in radians)

math.atan2

number math.atan2(number y, number x)

Description: Returns the arc tangent of y/x (in radians), but uses the signs of both parameters to find the quadrant of the result. It also handles correctly the case of x being zero.

math.ceil

int math.ceil(number x)

Description: Returns the smallest integer larger than or equal to x.

math.clamp

number math.clamp(number x, number min, number max)

Description: Returns a number between min and max, inclusive.

math.cos

number math.cos(number x)

Description: Returns the cosine of x (assumed to be in radians).

math.cosh

number math.cosh(number x)

Description: Returns the hyperbolic cosine of x.

math.deg

number math.deg(number x)

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

math.exp

number math.exp(number x)

Description: Returns the value e^x.

math.floor

int math.floor(number x)

Description: Returns the largest integer smaller than or equal to x.

math.fmod

number math.fmod(number x, number y)

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

math.frexp

number, int math.frexp(number x)

Description: Returns m and e such that x = m*2^e, e is an integer and the absolute value of m is in the range [0.5, 1) (or zero when x is zero).

math.ldexp

number math.ldexp(number x, int e)

Description: Returns m*2^e (e should be an integer).

math.log

number math.log(number x)

Description: Returns the natural logarithm of x.

math.log10

number math.log10(number x)

Description: Returns the base-10 logarithm of x.

math.max

number math.max(number x, number ...)

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

math.min

number math.min(number x, number ...)

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

math.modf

number, number math.modf(number x)

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

math.noise

number math.noise(number x = 0, number y = 0, number z = 0)

Description: Returns a perlin noise value between -0.5 and 0.5. 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)`.

The 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.

math.pow

number math.pow(number x, number y)

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

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

math.random

void math.random(number m = 0.0, number n = 1.0)

Description: This function is an interface to the simple pseudo-random generator function rand provided by ANSI C. (No guarantees can be given for its statistical properties.) When called without arguments, returns a uniform pseudo-random real number in the range [0,1). When called with an integer number m, math.random returns a uniform pseudo-random integer in the range [1, m]. When called with two integer numbers m and n, math.random returns a uniform pseudo-random integer in the range [m, n].

math.randomseed

void math.randomseed(number x)

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

math.sign

int math.sign(number x)

Description: Returns -1 if x < 0, 0 if x == 0, or 1 if x > 0.

math.sin

number math.sin(number x)

Description: Returns the sine of x (assumed to be in radians).

math.sinh

number math.sinh(number x)

Description: Returns the hyperbolic sine of x.

math.sqrt

number math.sqrt(number x)

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

math.tan

number math.tan(number x)

Description: Returns the tangent of x (assumed to be in radians).

math.tanh

number math.tanh(number x)

Description: Returns the hyperbolic tangent of x.

Constants

math.huge

number math.huge

Description: The value HUGE_VAL, a value larger than or equal to any other numerical value.

math.pi

number math.pi

Description: The value of pi.