math庫

函數名描述示例結果
pi圓周率math.pi3.1415926535898
abs取絕對值math.abs(-2012)2012
ceil向上取整math.ceil(9.1)10
floor向下取整math.floor(9.9)9
max取參數最大值math.max(2,4,6,8)8
min取參數最小值math.min(2,4,6,8)2
pow計算x的y次冪math.pow(2,16)65536
sqrt開平方math.sqrt(65536)256
mod取模math.mod(65535,2)1
modf取整數和小數部分math.modf(20.12)20  0.12
randomseed設隨機數種子math.randomseed(os.time()) 
random取隨機數math.random(5,90)5~90
rad角度轉弧度math.rad(180)3.1415926535898
deg弧度轉角度math.deg(math.pi)180
expe的x次方math.exp(4)54.598150033144
log計算x的自然對數math.log(54.598150033144)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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章