May 12, 2021 Lua
All functions of the math library in Lua 5.1 are as follows:
math.pi is the circular rate constant of 3.14159265358979323846
Table 1
Math library |
Description |
Example |
Method |
Abs |
Take the absolute value |
math.abs(-15) |
15 |
acos |
The anti-cosine function |
math.acos(0.5) |
1.04719755 |
asin |
The antisine function |
math.asin(0.5) |
0.52359877 |
atan2 |
The reverse cut value of x / y |
math.atan2(90.0, 45.0) |
1.10714871 |
atan |
Cut the function anyway |
math.atan(0.5) |
0.463647609 |
ceil |
The maximum integer that is not less than x |
math.ceil(5.8) |
6 |
cosh |
Double-curve cosine function |
math.cosh(0.5) |
1.276259652 |
cos |
Cosine function |
math.cos(0.5) |
0.87758256 |
deg |
Radian angle |
math.deg(math.pi) |
180 |
Exp |
Calculate the x-square value with e as the base |
math.exp(2) |
2.718281828 |
floor |
The maximum integer that is not greater than x |
math.floor(5.6) |
5 |
fmod ( mod ) |
The molding operation |
math.mod(14, 5) |
4 |
frexp |
Break down the double number val into the numeric part (the last part) and the index n with 2 as the bottom, i.e. val=x*2n |
math.frexp(10.0) |
0.625 4 |
ldexp |
Calculate the n-side of the value x 2 |
math.ldexp(10.0, 3) |
80 = 10 * (2 ^3) |
log10 |
Calculates a pair of 10-based pairs |
math.log10(100)
|
2 |
log |
Calculate the natural pair of numbers |
math.log(2.71) |
0.9969 |
max |
Get the maximum value in the argument |
math.max(2.71, 100, -98, 23) |
100 |
min |
Get the minimum value in the argument |
math.min(2.71, 100, -98, 23) |
-98 |
modf |
Divide the numbers into integers and numbers |
math.modf(15.98) |
15 98 |
pow |
Get x's y-side |
math.pow(2, 5) |
32 |
Rad |
Angle arc |
math.rad(180) |
3.14159265358 |
random |
Gets the random number |
math.random(1, 100) math.random(100) |
Get a random number of 1-100 |
randomseed |
Set the random number seed |
math.randomseed(os.time()) |
You must use this function to set the random number seed before you can use the math.random function |
sinh |
Bi-curved sine function |
math.sinh(0.5) |
0.5210953 |
sin |
Sine function |
math.sin(math.rad(30)) |
0.5 |
sqrt |
Open square function |
math.sqrt(16) |
4 |
tanh |
The bi-curved positive-cut function |
math.tanh(0.5) |
0.46211715 |
tan |
The positive-cut function |
math.tan(0.5) |
0.5463024 |
Reference blog: http://www.cnblogs.com/whiteyun/archive/2009/08/10/1543040.html