模块 math
require "math"
公开 API
| API | 实现 | 说明 |
|---|---|---|
math.random | math_random | 随机数:无参返回 [0,1) 浮点,一个整参返回 [1,m],两个返回 [m,n] 整数 |
math.randomseed | math_randomseed | 设置随机种子,并可选(启用则)返回随机数 |
math.abs | math_abs | 返回 x 的绝对值 |
math.acos | math_acos | 返回 x 的反余弦(弧度) |
math.asin | math_asin | 返回 x 的反正弦(弧度) |
math.atan | math_atan | 返回 x 的反正切;两参形式返回 atan(y/x) |
math.ceil | math_ceil | 返回不小于 x 的最小整数 |
math.cos | math_cos | 返回 x 的余弦 |
math.deg | math_deg | 弧度转角度 |
math.exp | math_exp | 返回 e^x |
math.tointeger | math_toint | 将值转换为整数,无法转换返回 nil |
math.floor | math_floor | 返回不大于 x 的最大整数 |
math.fmod | math_fmod | 返回 x 对 y 取模(浮点) |
math.frexp | math_frexp | 将 x 分解为尾数 m 与指数 e,返回 m 和 e |
math.ult | math_ult | 返回布尔:m |
math.ldexp | math_ldexp | 返回 m * 2^e |
math.log | math_log | 返回 x 的自然对数;带 base 时为以 base 为底 |
math.max | math_max | 返回参数中的最大值 |
math.min | math_min | 返回参数中的最小值 |
math.modf | math_modf | 返回 x 的整数部分与小数部分 |
math.rad | math_rad | 角度转弧度 |
math.sin | math_sin | 返回 x 的正弦 |
math.sqrt | math_sqrt | 返回 x 的平方根 |
math.tan | math_tan | 返回 x 的正切 |
math.type | math_type | 返回数值内部表示类型:'integer'/'float' |
math.atan2 | math_atan | 返回 atan(y/x)(兼容旧接口) |
math.cosh | math_cosh | 双曲余弦 |
math.sinh | math_sinh | 双曲正弦 |
math.tanh | math_tanh | 双曲正切 |
math.pow | math_pow | 返回 x^y |
math.log10 | math_log10 | 返回以 10 为底的 x 对数 |
math.random | NULL | 随机数:无参返回 [0,1) 浮点,一个整参返回 [1,m],两个返回 [m,n] 整数 |
math.randomseed | NULL | 设置随机种子,并可选(启用则)返回随机数 |
math.pi | NULL | 圆周率 π 常量 |
math.huge | NULL | 最大浮点值(math.huge = +inf) |
math.maxinteger | NULL | 最大整数常量 |
math.mininteger | NULL | 最小整数常量 |