# Lua math standard library

version 1.2.162

Documentation for the Lua math standard library.

From Lua 5.1 Reference Manual by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes.

Freely available under the terms of the Lua license.

## Functions

### math.abs

math.abs(x)

Returns the absolute value of x.

#### Parameters

 `x`
`x`

### math.acos

math.acos(x)

Returns the arc cosine of x (in radians).

#### Parameters

 `x`
`x`

### math.asin

math.asin(x)

Returns the arc sine of x (in radians).

#### Parameters

 `x`
`x`

### math.atan

math.atan(x)

Returns the arc tangent of x (in radians).

#### Parameters

 `x`
`x`

### 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` `x`
`y`
`x`

### math.ceil

math.ceil(x)

Returns the smallest integer larger than or equal to x.

#### Parameters

 `x`
`x`

### math.cos

math.cos(x)

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

#### Parameters

 `x`
`x`

### math.cosh

math.cosh(x)

Returns the hyperbolic cosine of x.

#### Parameters

 `x`
`x`

### math.deg

math.deg(x)

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

#### Parameters

 `x`
`x`

### math.exp

math.exp(x)

Returns the value ex.

#### Parameters

 `x`
`x`

### math.floor

math.floor(x)

Returns the largest integer smaller than or equal to x.

#### Parameters

 `x`
`x`

### math.fmod

math.fmod(x, y)

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

#### Parameters

 `x` `y`
`x`
`y`

### 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`
`x`

### math.huge

math.huge()

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

### math.ldexp

math.ldexp(m, e)

Returns m2e (e should be an integer).

#### Parameters

 `m` `e`
`m`
`e`

### math.log

math.log(x)

Returns the natural logarithm of x.

#### Parameters

 `x`
`x`

### math.log10

math.log10(x)

Returns the base-10 logarithm of x.

#### Parameters

 `x`
`x`

### math.max

math.max(x, ...)

Returns the maximum value among its arguments.

#### Parameters

 `x` `...`
`x`
`...`

### math.min

math.min(x, ...)

Returns the minimum value among its arguments.

#### Parameters

 `x` `...`
`x`
`...`

### math.modf

math.modf(x)

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

#### Parameters

 `x`
`x`

### math.pow

math.pow(x, y)

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

#### Parameters

 `x` `y`
`x`
`y`

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

#### Parameters

 `x`
`x`

### 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]` `[n]`
`[m]`
`[n]`

### math.randomseed

math.randomseed(x)

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

#### Parameters

 `x`
`x`

### math.sin

math.sin(x)

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

#### Parameters

 `x`
`x`

### math.sinh

math.sinh(x)

Returns the hyperbolic sine of x.

#### Parameters

 `x`
`x`

### 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`
`x`

### math.tan

math.tan(x)

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

#### Parameters

 `x`
`x`

### math.tanh

math.tanh(x)

Returns the hyperbolic tangent of x.

#### Parameters

 `x`
`x`

The value of PI.