規則。數學
全域可用的數學函數。這些函數可以透過math.
前綴並對數值進行操作。
方法
腹肌
abs(num) 回傳數字
數值的絕對值。
範圍 | |
---|---|
編號 | 數位 數值。 |
- 退貨
non-null number
輸入的絕對數值。
例子
math.abs(-1) == 1
math.abs(1) == 1
天花板
ceil(num) 回傳規則.Integer
數值的上限。
範圍 | |
---|---|
編號 | 數位 數值。 |
- 退貨
non-null rules.Integer
整數給定值的上限。
例子
math.ceil(2.0) == 2
math.ceil(2.1) == 3
math.ceil(2.7) == 3
地面
Floor(num) 回傳規則.Integer
數值的下限。
範圍 | |
---|---|
編號 | 數位 數值。 |
- 退貨
non-null rules.Integer
整數給定值的下限。
例子
math.floor(1.9) == 1
math.floor(2.0) == 2
math.floor(2.7) == 2
是無限的
isInfinite(num) 返回rules.Boolean
測試該值是否為±∞。
範圍 | |
---|---|
編號 | 數位 數值。 |
- 退貨
non-null rules.Boolean
若數字為正無窮大或負無窮大則為 true。
例子
math.isInfinite(∞) == true
math.isInfinite(100) == false
為 NaN
isNaN(num) 回傳規則.Boolean
測試該值是否為±∞。
範圍 | |
---|---|
編號 | 數位 數值。 |
- 退貨
non-null rules.Boolean
如果值不是數字則為 true。
例子
math.isNaN(NaN) == true
math.isNaN(100) == false
戰俘
pow(基數, 指數) 傳回規則.Float
傳回第一個參數的第二個參數次方的值。
範圍 | |
---|---|
根據 | 數位 數字基值。 |
指數 | 數位 數字指數值。 |
- 退貨
non-null rules.Float
將第一個參數的值浮點到第二個參數的冪。
例子
math.pow(2, 2) == 4
math.pow(1.5, 2) == 2.25
math.pow(4, 0.5) == 2
圓形的
round(num) 傳回規則.Integer
將輸入值舍入為最接近的整數。
範圍 | |
---|---|
編號 | 數位 數值。 |
- 退貨
non-null rules.Integer
最接近給定值的 int。
例子
math.round(1.9) == 2
math.round(2.4) == 2
math.round(2.5) == 3
開方
sqrt(num) 回傳規則.Float
輸入值的平方根。
範圍 | |
---|---|
編號 | 數位 數值。 |
- 退貨
non-null rules.Float
輸入值的平方根。
例子
math.sqrt(4) == 2.0
math.sqrt(2.25) == 1.5