Lua的math函数库

来源:互联网 发布:仿08影院模板源码 编辑:程序博客网 时间:2024/06/07 07:14

math函数

name describe e.g result abs 取绝对值 math.abs(-2015) 2015 ceil 向上取整 math.ceil(20.15) 21 floor 向下取整 math.floor(20.15) 20 round 四舍五入(可以用math.floor(x + 0.5)代替) max 取最大值 math.max(20, 15) 2 0 min 取最小值 math.min(20, 15) 15 pi 圆周率 math.pi 3.14… pow 计算x的y次幂 math.pow (2, 15) 32768 sqrt 开平方 math.sqrt(1024) 32 fmod 取模 math.fmod(20, 15) 5 modf 取整数,小数部分 math.modf(20.15) 20 15 randomseed 设随机数种子 math.randomseed(os.time()) random 取随机数 math.random(2, 15) 2~15 rad 角度转弧度 math.rad(180) math.pi deg 弧度转角度 math.deg(math.pi) 180 exp e的x次方 math.exp(4) e ^ 4 log x的自然对数 math.log(e ^ 4) 4 log10 10为底,x的对数 math.log10(1000) 3 frexp 格式化x * (2 ^ y) math.frexp(160) 0.625 8 ldexp 计算 x * (2 ^ y) math.ldexp(0.625,8) 160 sin 正弦 math.sin(math.rad(30)) 0.5 cos 余弦 math.cos(math.rad(60)) 0.5 tan 正切 math.tan(math.rad(45)) 1 asin 反正弦 math.deg(math.asin(0.5)) 30 acos 反余弦 math.deg(math.acos(0.5)) 60 atan 反正切 math.deg(math.atan(1)) 45 atan2 x/y的反正切值 math.atan2(90.0, 45.0) math.huge 最大数 math.randomseed(os.time()) i=math.random(1,6)
1 0