Lua math standard library

Documentation for the Lua math standard library. From [Lua 5.1 Reference Manual](https://www.lua.org/manual/5.1/) by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes. Copyright © 2006-2012 Lua.org, PUC-Rio. Freely available under the terms of the [Lua license](https://www.lua.org/license.html).

Version: beta

FUNCTIONS
math.abs() absolute value
math.acos() arc cosine
math.asin() arc sine
math.atan() arc tangent
math.atan2() arc tangent of v1/v2
math.ceil() next higher integer value
math.cos() cosine
math.cosh() hyperbolic cosine
math.deg() convert from radians to degrees
math.exp() raises e to a power
math.floor() next smaller integer value
math.fmod() the modulus (remainder) of doing: v1 / v2
math.frexp() break number into mantissa and exponent
math.ldexp() compute m* 2^n
math.log() natural log
math.log10() log to the base 10
math.max() the highest of one or more numbers
math.min() the lowest of one or more numbers
math.modf() returns the integral and fractional part of its argument
math.pow() raise a number to a power
math.rad() convert degrees to radians
math.random() generate a random number
math.randomseed() seeds the random number generator
math.sin() sine
math.sinh() hyperbolic sine
math.sqrt() square root
math.tan() tangent
math.tanh() hyperbolic tangent
CONSTANTS
math.huge a huge value
math.pi the value of pi

Functions

math.abs()

math.abs(x)

Returns the absolute value of x.

PARAMETERS

x number

math.acos()

math.acos(x)

Returns the arc cosine of x (in radians).

PARAMETERS

x number

math.asin()

math.asin(x)

Returns the arc sine of x (in radians).

PARAMETERS

x number

math.atan()

math.atan(x)

Returns the arc tangent of x (in radians).

PARAMETERS

x number

math.atan2()

math.atan2(y,x)

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

PARAMETERS

y number
x number

math.ceil()

math.ceil(x)

Returns the smallest integer larger than or equal to x.

PARAMETERS

x number

math.cos()

math.cos(x)

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

PARAMETERS

x number

math.cosh()

math.cosh(x)

Returns the hyperbolic cosine of x.

PARAMETERS

x number

math.deg()

math.deg(x)

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

PARAMETERS

x number

math.exp()

math.exp(x)

Returns the value ex.

PARAMETERS

x number

math.floor()

math.floor(x)

Returns the largest integer smaller than or equal to x.

PARAMETERS

x number

math.fmod()

math.fmod(x,y)

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

PARAMETERS

x number
y number

math.frexp()

math.frexp(x)

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

PARAMETERS

x number

math.ldexp()

math.ldexp(m,e)

Returns m2e (e should be an integer).

PARAMETERS

m number
e number

math.log()

math.log(x)

Returns the natural logarithm of x.

PARAMETERS

x number

math.log10()

math.log10(x)

Returns the base-10 logarithm of x.

PARAMETERS

x number

math.max()

math.max(x,...)

Returns the maximum value among its arguments.

PARAMETERS

x number
...

math.min()

math.min(x,...)

Returns the minimum value among its arguments.

PARAMETERS

x number
...

math.modf()

math.modf(x)

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

PARAMETERS

x number

math.pow()

math.pow(x,y)

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

PARAMETERS

x number
y number

math.rad()

math.rad(x)

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

PARAMETERS

x number

math.random()

math.random(m,n)

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

PARAMETERS

[m] number
[n] number

math.randomseed()

math.randomseed(x)

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

PARAMETERS

x number

math.sin()

math.sin(x)

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

PARAMETERS

x number

math.sinh()

math.sinh(x)

Returns the hyperbolic sine of x.

PARAMETERS

x number

math.sqrt()

math.sqrt(x)

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

PARAMETERS

x number

math.tan()

math.tan(x)

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

PARAMETERS

x number

math.tanh()

math.tanh(x)

Returns the hyperbolic tangent of x.

PARAMETERS

x number

Constants

math.huge

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


math.pi

The value of PI.