Mathematical Library
Published Aug 15, 2023Updated Oct 21, 2023
Contribute to Docs
The mathematical library contains Lua’s built-in functions that relate to math. These math functions include those relating to trigonometry (like sin
and cos
), exponents (exp
or ^
), logs (logN
), rounding (floor
, ceil
), and a variety of other operations.
Math Functions
The math
library includes a range of convenient functions that include the following:
Mathematical Library
- .log()
- Calculates the natural logarithmic value of a number.
- abs()
- Returns the absolute value of a given number.
- acos()
- Returns the arc cosine of the argument, in radians.
- asin()
- Returns the inverse sine in radians of a given value.
- atan()
- Calculates the arctangent (inverse tangent) of a given number.
- ceil()
- Returns the smallest integer greater than or equal to a given value.
- cos()
- Returns the cosine of an angle represented in radians.
- deg()
- Converts angles from radians to degrees.
- exp()
- Used to calculate the exponential value of a number.
- floor()
- Used to round down a value to the closest integer less than or equal to that value.
- fmod()
- Returns the remainder of the quotient of two arguments.
- max()
- Used to return the maximum value among a set of numerical input values.
- maxinteger
- Returns the largest possible integer value.
- min()
- Returns the smallest value from a series of given numbers.
- mininteger
- Returns the smallest possible integer value.
- modf()
- Used to extract the integral and fractional parts of a given number.
- rad()
- Converts a number given in degrees to radians.
- random()
- Generates pseudo-random numbers based on a specified range.
- randomseed()
- Used to initialize a seed for the random number generator.
- sin()
- Returns the sine of an angle given in radians.
- sqrt()
- Returns the result of the square root operation on a numeric variable.
- tan()
- Calculates the tangent of an angle.
- tointeger()
- Used to convert a given value to an integer if possible.
- type()
- Takes a number argument and returns its type.
- ult()
- Compares the absolute value of two integers and returns true if the first is less than the second.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.