Lua中的數學庫總結_Lua

來源:互聯網
上載者:User

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

atan2

x / 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*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)

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.