math.pi = 3.14159265358979323846| 函數 | 功能 | 示例 | 結果 |
|---|---|---|---|
| math.abs(x) | 絕對值 | math.abs(-15) | 15 |
| math.acos(x) | 反余弦 | math.acos(0.5) | 1.04719755 |
| math.asin(x) | 反正弦 | math.asin(0.5) | 0.52359877 |
| math.atan2(y, x) | y/x 反正切 | math.atan2(90, 45) | 1.10714871 |
| math.atan(x) | 反正切 | math.atan(0.5) | 0.463647609 |
| math.ceil(x) | 向上取整 | math.ceil(5.8) | 6 |
| math.cosh(x) | 雙曲余弦 | math.cosh(0.5) | 1.276259652 |
| math.cos(x) | 余弦 | math.cos(0.5) | 0.87758256 |
| math.deg(x) | 弧度轉角度 | math.deg(math.pi) | 180 |
| math.exp(x) | e^x | math.exp(2) | 7.389056 |
| math.floor(x) | 向下取整 | math.floor(5.6) | 5 |
| math.fmod(x, y) | 取模(餘數) | math.fmod(14, 5) | 4 |
| math.frexp(x) | 分解尾數與指數 | math.frexp(10) | 0.625, 4 |
| math.ldexp(m, e) | m * 2^e | math.ldexp(10, 3) | 80 |
| math.log10(x) | 以 10 為底對數 | math.log10(100) | 2 |
| math.log(x) | 自然對數 | math.log(2.71) | 0.9969 |
| math.max(...) | 最大值 | math.max(2.71, 100, -98) | 100 |
| math.min(...) | 最小值 | math.min(2.71, 100, -98) | -98 |
| math.modf(x) | 分離整數/小數部 | math.modf(15.98) | 15, 0.98 |
| math.pow(x, y) | x^y | math.pow(2, 5) | 32 |
| math.rad(x) | 角度轉弧度 | math.rad(180) | 3.14159265 |
| math.random([m, n]) | 隨機數 | math.random(1,100) | 1-100 整數 |
| math.randomseed(x) | 設置隨機種子 | math.randomseed(os.time()) | 必須先調用 |
| math.sinh(x) | 雙曲正弦 | math.sinh(0.5) | 0.5210953 |
| math.sin(x) | 正弦 | math.sin(math.rad(30)) | 0.5 |
| math.sqrt(x) | 平方根 | math.sqrt(16) | 4 |
| math.tanh(x) | 雙曲正切 | math.tanh(0.5) | 0.46211715 |
| math.tan(x) | 正切 | math.tan(0.5) | 0.5463024 |
math.rad/math.deg 轉換。math.random 調用前必須設置種子,否則每次運行序列相同。math.fmod 與 % 不同,前者結果符號與被除數一致。