# Lua Math library - Lua (programming language)

## What functions are available in Math library?

Math operations are often needed in scientific and engineering calculations and these can be availed using the standard Lua library math. Below is the list of functions available in math library.
S.N. Library / Method & Purpose
1.

math.abs (x)

Returns the absolute value of x.

2.

math.acos (x)

Returns the arc cosine of x (in radians).

3.

math.asin (x)

Returns the arc sine of x (in radians).

4.

math.atan (x)

Returns the arc tangent of x (in radians).

5.

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

6.

math.ceil (x)

Returns the smallest integer larger than or equal to x.

7.

math.cos (x)

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

8.

math.cosh (x)

Returns the hyperbolic cosine of x.

9.

math.deg (x)

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

10.

math.exp (x)

Returns the value e power x.

11.

math.floor (x)

Returns the largest integer smaller than or equal to x.

12.

math.fmod (x, y)

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

13.

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

14.

math.huge

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

15.

math.ldexp (m, e)

Returns m2e (e should be an integer).

16.

math.log (x)

Returns the natural logarithm of x.

17.

math.log10 (x)

Returns the base-10 logarithm of x.

18.

math.max (x, ...)

Returns the maximum value among its arguments.

19.

math.min (x, ...)

Returns the minimum value among its arguments.

20.

math.modf (x)

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

21.

math.pi

The value of pi.

22.

math.pow (x, y)

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

23.

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

24.

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

This function is an interface to the simple pseudo-random generator function rand provided by ANSI C.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].

25.

math.randomseed (x)

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

26.

math.sin (x)

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

27.

math.sinh (x)

Returns the hyperbolic sine of x.

28.

math.sqrt (x)

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

29.

math.tan (x)

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

30.

math.tanh (x)

Returns the hyperbolic tangent of x.

## Trigonometric functions

A simple example using trigonometric function is shown below.
When you run the above program, below output will be displayed.

## Other common math functions

A simple example using common math functions is shown below.
When you run the above program, below output will be displayed.
Above examples are just a few of the common examples. You can use math library based on your reuirement. Try using all the functions to get more clarity.

Lua (programming language) Topics