Lua中的數(shù)學(xué)庫(kù)總結(jié)
Lua5.1中數(shù)學(xué)庫(kù)的所有函數(shù)如下表:
math.pi 為圓周率常量 = 3.14159265358979323846
abs |
取絕對(duì)值 |
math.abs(-15) |
15 |
acos |
反余弦函數(shù) |
math.acos(0.5) |
1.04719755 |
asin |
反正弦函數(shù) |
math.asin(0.5) |
0.52359877 |
atan2 |
x / y的反正切值 |
math.atan2(90.0, 45.0) |
1.10714871 |
atan |
反正切函數(shù) |
math.atan(0.5) |
0.463647609 |
ceil |
不小于x的最大整數(shù) |
math.ceil(5.8) |
6 |
cosh |
雙曲線余弦函數(shù) |
math.cosh(0.5) |
1.276259652 |
cos |
余弦函數(shù) |
math.cos(0.5) |
0.87758256 |
deg |
弧度轉(zhuǎn)角度 |
math.deg(math.pi) |
180 |
exp |
計(jì)算以e為底x次方值 |
math.exp(2) |
2.718281828 |
floor |
不大于x的最大整數(shù) |
math.floor(5.6) |
5 |
fmod (mod) |
取模運(yùn)算 |
math.mod(14, 5) |
4 |
frexp |
把雙精度數(shù)val分解為數(shù)字部分(尾數(shù))和以2為底的指數(shù)n,即val=x*2n |
math.frexp(10.0) |
0.625 4 |
ldexp |
計(jì)算value * 2的n次方 |
math.ldexp(10.0, 3) |
80 = 10 * (2 ^3) |
log10 |
計(jì)算以10為基數(shù)的對(duì)數(shù) |
math.log10(100) |
2 |
log |
計(jì)算一個(gè)數(shù)字的自然對(duì)數(shù) |
math.log(2.71) |
0.9969 |
max |
取得參數(shù)中最大值 |
math.max(2.71, 100, -98, 23) |
100 |
min |
取得參數(shù)中最小值 |
math.min(2.71, 100, -98, 23) |
-98 |
modf |
把數(shù)分為整數(shù)和小數(shù) |
math.modf(15.98) |
15 98 |
pow |
得到x的y次方 |
math.pow(2, 5) |
32 |
rad |
角度轉(zhuǎn)弧度 |
math.rad(180) |
3.14159265358 |
random |
獲取隨機(jī)數(shù) |
math.random(1, 100) |
獲取1-100的隨機(jī)數(shù) |
randomseed |
設(shè)置隨機(jī)數(shù)種子 |
math.randomseed(os.time()) |
在使用math.random函數(shù)之前必須使用此函數(shù)設(shè)置隨機(jī)數(shù)種子 |
sinh |
雙曲線正弦函數(shù) |
math.sinh(0.5) |
0.5210953 |
sin |
正弦函數(shù) |
math.sin(math.rad(30)) |
0.5 |
sqrt |
開(kāi)平方函數(shù) |
math.sqrt(16) |
4 |
tanh |
雙曲線正切函數(shù) |
math.tanh(0.5) |
0.46211715 |
tan |
正切函數(shù) |
math.tan(0.5) |
0.5463024 |
相關(guān)文章
實(shí)現(xiàn)Lua中數(shù)據(jù)類型的源碼分享
在Lua中有8種基礎(chǔ)類型,像其他動(dòng)態(tài)語(yǔ)言一樣,在語(yǔ)言中沒(méi)有類型定義的語(yǔ)法,每個(gè)值都攜帶了它自身的類型信息。下面我們就來(lái)嘗試通過(guò)Lua 5.2.1的源碼來(lái)看類型的實(shí)現(xiàn)2015-04-04Lua的迭代器使用中應(yīng)該避免的問(wèn)題和技巧
這篇文章主要介紹了Lua的迭代器使用中應(yīng)該避免的問(wèn)題和技巧,本文介紹了避免創(chuàng)建閉合函數(shù)、利用恒定狀態(tài)創(chuàng)造更多變量、不需要for循環(huán)的迭代器等內(nèi)容,需要的朋友可以參考下2014-09-09Mac平臺(tái)中編譯安裝Lua運(yùn)行環(huán)境及Hello Lua實(shí)例
這篇文章主要介紹了Mac平臺(tái)中編譯安裝Lua運(yùn)行環(huán)境及Hello Lua實(shí)例,本文給出了兩種Hello Lua示例,一種是控制臺(tái)直接輸出,通過(guò)文件編譯輸出,需要的朋友可以參考下2014-10-10