lua5.1中數學庫的所有函式如下表:
math.pi 為圓周率常量
= 3.14159265358979323846
abs取絕對值
math.abs(-15)
acos
反余弦函式
math.acos(0.5)
1.04719755
asin
反正弦函式
math.asin(0.5)
0.52359877
atan2
x / y的反正切值
math.atan2(90.0, 45.0)
1.10714871
atan
反正切函式
math.atan(0.5)
0.463647609
ceil
不小於x
的最大整數
math.ceil(5.8)
cosh
雙曲線余弦函式
math.cosh(0.5)
1.276259652
cos余弦函式
math.cos(0.5)
0.87758256
deg弧度轉角度
math.deg(math.pi)
exp計算以e為底x
次方值
math.exp(2)
2.718281828
floor
不大於x
的最大整數
math.floor(5.6)
fmod (
mod)
取模運算
math.mod(14, 5)
frexp
把雙精度數val
分解為數字部分(尾數)和以
2為底的指數n,即
val=x*2n
math.frexp(10.0)
0.625 4
ldexp
計算value * 2的n
次方 math.ldexp(10.0, 3)
80 = 10 * (2 ^3)
log10
計算以10
為基數的對數
math.log10(100)
log計算乙個數字的自然對數
math.log(2.71)
0.9969
max取得引數中最大值
math.max(2.71, 100, -98, 23)
min取得引數中最小值
math.min(2.71, 100, -98, 23)
-98modf
把數分為整數和小數
math.modf(15.98)
15 98
pow得到x的y
次方 math.pow(2, 5)
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.5sqrt
開平方函式
math.sqrt(16)
tanh
雙曲線正切函式
math.tanh(0.5)
0.46211715
tan正切函式
math.tan(0.5)
0.5463024
Lua基礎之math 數學函式庫
abs 取絕對值 math.abs 15 acos 反余弦函式 math.acos 0.5 1.04719755 asin 反正弦函式 math.asin 0.5 0.52359877 atan2 x y的反正切值 math.atan2 90.0,45.0 1.10714871 atan 反正切函式...
Lua資料之數學庫
lua 數學庫由一組標準的數學函式構成。數學庫的引入豐富了 lua 程式語言的功能,同時也方便了程式的編寫。常用數學 math.rad x 角度x轉換成弧度 math.deg x 弧度x轉換成角度 math.max x,返回引數中值最大的那個數,引數必須是number型 math.min x,返回引...
Lua基礎總結
本文總結了lua資料型別,表示式,基本語法。lua單行注釋 多行注釋 全域性變數 不需要宣告,訪問乙個沒有初始化的全域性變數也不會出錯,只是結果是nil。刪除乙個全域性變數,只給他賦值nil,即b nil。lua資料型別 8種 nil,boolean,number,string,undata,fun...