个人学习:lua数学函数库
函数 | 作用 |
---|---|
math.abs(-15) = 15 | 取绝对值 |
math.acos(0.5) = 1.04719755 | 反余弦函数 |
math.asin(0.5) = 0.52359877 | 反正弦函数 |
math.atan2(90.0, 45.0) = 1.10714871 | x / y的反正切值 |
math.atan(0.5) = 0.463647609 | 反正切函数 |
math.ceil(5.8) = 6 | 不小于x的最小整数 |
math.cosh(0.5) = 1.276259652 | 双曲线余弦函数 |
math.cos(0.5) = 0.87758256 | 余弦函数 |
math.deg(math.pi) = 180 | 弧度转角度 |
math.exp(2) = 2.718281828 | 计算以e为底x次方值 |
math.floor(5.6) = 5 | 不大于x的最大整数 |
math.mod/fmod(14, 5) = 4 | 取模运算 |
math.frexp(10.0) = 0.625 4 | 把双精度数val分解为数字部分(尾数)和以2为底的指数n,即val=x*2n |
math.ldexp(10, 3) 运算结果为: 80 = 10 * (2 ^3) | 计算value * 2的n次方 |
math.log10(100) = 2 | 计算以10为基数的对数 |
math.log(2.71) = 0.9969 | 计算一个数字的自然对数 |
math.max(2.71, 100, -98, 23) = 100 | 取得参数中最大值 |
math.min(2.71, 100, -98, 23) = -98 | 取得参数中最小值 |
math.modf(15.98)运算结果为:15 98 | 把数分为整数和小数 |
math.pow(2, 5) = 32 | 得到x的y次方 |
math.rad(180) = 3.14159265358 | 角度转弧度 |
math.random(1, 100)或math.random(100) | 获取1-100的随机数 |
math.randomseed(os.time()) | 设置随机种子,在使用math.random函数之前必须使用此函数设置随机数种子 |
math.sinh(0.5) = 0.5210953 | 双曲线正弦函数 |
math.sin(math.rad(30)) = 0.5 | 正弦函数 |
math.sqrt(16) = 4 | 开平方 |
math.tanh(0.5) = 0.46211715 | 双曲线正切函数 |
math.tan(0.5) = 0.5463024 | 正切函数 |