您的位置:首页 > 编程语言 > Lua

Lua基础之math(数学函数库)

2016-12-31 16:13 232 查看
Lua5.1中数学库的所有函数如下表:
math.pi 为圆周率常量 = 3.14159265358979323846

abs取绝对值math.abs(-15)15
acos反余弦函数math.acos(0.5)1.04719755
asin反正弦函数math.asin(0.5)0.52359877
atan2x / y的反正切值math.atan2(90.0, 45.0)1.10714871
atan反正切函数math.atan(0.5)0.463647609
ceil不小于x的最大整数math.ceil(5.8)6
cosh双曲线余弦函数math.cosh(0.5)1.276259652
cos余弦函数math.cos(0.5)0.87758256
deg弧度转角度math.deg(math.pi)180
exp计算以e为底x次方值math.exp(2)2.718281828
floor不大于x的最大整数math.floor(5.6)5
fmod (mod)取模运算math.mod(14, 5)4
frexp把双精度数val分解为数字部分(尾数)和以2为底的指数n,即val=x*2nmath.frexp(10.0)0.625 4
ldexp计算value * 2的n次方math.ldexp(10.0, 3)80 = 10 * (2 ^3)
log10计算以10为基数的对数math.log10(100)2
log计算一个数字的自然对数math.log(2.71)0.9969
max取得参数中最大值math.max(2.71, 100, -98, 23)100
min取得参数中最小值math.min(2.71, 100, -98, 23)-98
modf把数分为整数和小数math.modf(15.98)15 98
pow得到x的y次方math.pow(2, 5)32
rad角度转弧度math.rad(180)3.14159265358
random获取随机数math.random(1, 100)

math.random(100)
获取1-100的随机数
randomseed设置随机数种子math.randomseed(os.time())在使用math.random函数之前必须使用此函数设置随机数种子
sinh双曲线正弦函数math.sinh(0.5)0.5210953
sin正弦函数math.sin(math.rad(30))0.5
sqrt开平方函数math.sqrt(16)4
tanh双曲线正切函数math.tanh(0.5)0.46211715
tan正切函数math.tan(0.5)0.5463024
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: