Math

Documentation for the Lua math standard library. From Lua 5.1 Reference Manual 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.

math.abs(x)

absolute value

Returns the absolute value of x.

PARAMETERS

x -


math.acos(x)

arc cosine

Returns the arc cosine of x (in radians).

PARAMETERS

x -


math.asin(x)

arc sine

Returns the arc sine of x (in radians).

PARAMETERS

x -


math.atan(x)

arc tangent

Returns the arc tangent of x (in radians).

PARAMETERS

x -


math.atan2(y, x)

arc tangent of v1/v2

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 -

x -


math.ceil(x)

next higher integer value

Returns the smallest integer larger than or equal to x.

PARAMETERS

x -


math.cos(x)

cosine

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

PARAMETERS

x -


math.cosh(x)

hyperbolic cosine

Returns the hyperbolic cosine of x.

PARAMETERS

x -


math.deg(x)

convert from radians to degrees

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

PARAMETERS

x -


math.exp(x)

raises e to a power

Returns the value ex.

PARAMETERS

x -


math.floor(x)

next smaller integer value

Returns the largest integer smaller than or equal to x.

PARAMETERS

x -


math.fmod(x, y)

the modulus (remainder) of doing: v1 / v2

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

PARAMETERS

x -

y -


math.frexp(x)

break number into mantissa and exponent

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 -


math.huge

a huge value

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


math.ldexp(m, e)

compute m* 2^n

Returns m2e (e should be an integer).

PARAMETERS

m -

e -


math.log(x)

natural log

Returns the natural logarithm of x.

PARAMETERS

x -


math.log10(x)

log to the base 10

Returns the base-10 logarithm of x.

PARAMETERS

x -


math.max(x, ...)

the highest of one or more numbers

Returns the maximum value among its arguments.

PARAMETERS

x -

... -


math.min(x, ...)

the lowest of one or more numbers

Returns the minimum value among its arguments.

PARAMETERS

x -

... -


math.modf(x)

returns the integral and fractional part of its argument

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

PARAMETERS

x -


math.pi

the value of pi

The value of PI.


math.pow(x, y)

raise a number to a power

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

PARAMETERS

x -

y -


math.rad(x)

convert degrees to radians

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

PARAMETERS

x -


math.random([m], [n])

generate a random number

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

[n] -


math.randomseed(x)

seeds the random number generator

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

PARAMETERS

x -


math.sin(x)

sine

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

PARAMETERS

x -


math.sinh(x)

hyperbolic sine

Returns the hyperbolic sine of x.

PARAMETERS

x -


math.sqrt(x)

square root

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

PARAMETERS

x -


math.tan(x)

tangent

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

PARAMETERS

x -


math.tanh(x)

hyperbolic tangent

Returns the hyperbolic tangent of x.

PARAMETERS

x -