Lua中math庫函式列表

2021-06-26 11:43:01 字數 1390 閱讀 5291

函式名

描述示例

結果pi

圓周率math.pi

3.1415926535898

abs取絕對值

math.abs(-2012)

2012

ceil

向上取整

math.ceil(9.1)

10floor

向下取整

math.floor(9.9)

9max

取引數最大值

math.max(2,4,6,8)

8min

取引數最小值

math.min(2,4,6,8)

2pow

計算x的y次冪

math.pow(2,16)

65536

sqrt

開平方math.sqrt(65536)

256mod

取模math.mod(65535,2)

1modf

取整數和小數部分

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)

180exp

e的x次方

math.exp(4)

54.598150033144

log計算x的自然對數

math.log(54.598150033144)

4log10

計算10為底,x的對數

math.log10(1000)

3frexp

將引數拆成x * (2 ^ y)的形式

math.frexp(160)

0.625 

8ldexp

計算x * (2 ^ y)

math.ldexp(0.625,8)

160sin

正弦math.sin(math.rad(30))

0.5cos

余弦math.cos(math.rad(60))

0.5tan

正切math.tan(math.rad(45))

1asin

反正弦math.deg(math.asin(0.5))

30acos

反余弦math.deg(math.acos(0.5))

60atan

反正切math.deg(math.atan(1))

45

Lua中table庫函式詳解

table.concat table,sep,start,end table.concat 函式列出table中陣列部分從下表start到end的所有元素,元素中間以字元sep隔開,預設字元為空字元,其中table引數必填,其餘三個引數可以不填。例 t print table.concat t,1,...

format函式 11 math庫函式

一 math庫介紹 內建數學類函式庫,math庫不支援複數型別,僅支援整數和浮點數運算。math庫一共提供了 4個數字常數 44個函式,分為4類 16個數值表示函式 8個冪對數函式 16個三角對數函式 4個高等特殊函式 二 math庫使用 庫中函式不能直接使用,需使用保留字import引用 impo...

Math標準庫函式功能彙總

計算機程式語言的一種函式,主要應用資料運算。math函式可以被應用於解決部分電腦程式問題 下面列出一些函式的功能及使用說明 函式功能 使用說明 e自然常數e math.e 2.718281828459045 pi圓周率pi math.pi 3.141592653589793 degrees 弧度轉角...