# math

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

## Functions

 number math.abs ( ) Returns the absolute value of x
 number math.acos ( ) Returns the arc cosine of x
 number math.asin ( ) Returns the arc sine of x
 number math.atan ( ) Returns the arc tangent of x (in radians)
 number math.atan2 ( number y, ) 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.
 int math.ceil ( ) Returns the smallest integer larger than or equal to x.
 number math.clamp ( number x, number min, number max ) Returns a number between min and max, inclusive.
 number math.cos ( ) Returns the cosine of x (assumed to be in radians).
 number math.cosh ( ) Returns the hyperbolic cosine of x.
 number math.deg ( ) Returns the angle x (given in radians) in degrees.
 number math.exp ( ) Returns the value e^x.
 int math.floor ( ) Returns the largest integer smaller than or equal to x.
 number math.fmod ( number x, ) Returns the remainder of the division of x by y that rounds the quotient towards zero.
 number , int math.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 [0.5, 1) (or zero when x is zero).
 number math.ldexp ( number x, int e ) Returns m*2^e (e should be an integer).
 number math.log ( number x, number base = 2.7182818 ) Returns the logarithm of x using the given base, or the mathematical constant e if no base is provided (natural logarithm).
 number math.log10 ( ) Returns the base-10 logarithm of x.
 number math.max ( number x, number ... ) Returns the maximum value among the numbers passed to the function.
 number math.min ( number x, number ... ) Returns the minimum value among the numbers passed to the function.
 number , number math.modf ( ) Returns two numbers, the integral part of x and the fractional part of x.
 number math.noise ( number x, number y = 0, number z = 0 ) Returns a perlin noise value. The returned value is most often between the range [-1, 1]. The returned value is sometimes will be outside of the range [-1,1], so if the interval is critical to you, you should 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)`. 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.
 number math.pow ( number x, ) Returns x^y. (You can also use the expression x^y to compute this value.)
 number math.rad ( ) Returns the angle x (given in degrees) in radians.
 number math.random ( number m = 0.0, number n = 1.0 ) 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].
 void math.randomseed ( ) Sets x as the seed for the pseudo-random generator: equal seeds produce equal sequences of numbers.
 number math.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: 0.5 rounds to 1; -0.5 rounds to -1.
 int math.sign ( ) Returns -1 if x < 0, 0 if x == 0, or 1 if x > 0.
 number math.sin ( ) Returns the sine of x (assumed to be in radians).
 number math.sinh ( ) Returns the hyperbolic sine of x.
 number math.sqrt ( ) Returns the square root of x. (You can also use the expression x^0.5 to compute this value.)
 number math.tan ( ) Returns the tangent of x (assumed to be in radians).
 number math.tanh ( ) Returns the hyperbolic tangent of x.

## Constants

 number math.huge The value HUGE_VAL, a value larger than or equal to any other numerical value.
 number math.pi The value of pi.