# Math 数学库

## 功能

Math 是全局无状态静态数学对象，提供数学常量、基础数学、取整、指数、对数、三角函数、双曲函数和随机数能力。

## 语法

```bt
Math.sqrt(9)
Math.pow(2, 3)
Math.PI
```

## API 列表

| API | 说明 |
| ------ | ------ |
| [Math 常量](/docs/math/constants) | 提供 E、PI、TAU 等数学常量。 |
| [Math.abs](/docs/math/abs) | 返回 value 的绝对值。 |
| [Math.pow](/docs/math/pow) | 返回 value 的 power 次幂。 |
| [Math.sqrt](/docs/math/sqrt) | 返回 value 的平方根。 |
| [Math.cbrt](/docs/math/cbrt) | 返回 value 的立方根。 |
| [Math.min](/docs/math/min) | 返回所有参数中的最小值。 |
| [Math.max](/docs/math/max) | 返回所有参数中的最大值。 |
| [Math.clamp](/docs/math/clamp) | value 小于 min 时返回 min，大于 max 时返回 max，否则返回 value。 |
| [Math.sign](/docs/math/sign) | 负数返回 -1，零返回 0，正数返回 1。 |
| [Math.hypot](/docs/math/hypot) | 返回 sqrt(x * x + y * y) 的斜边长度。 |
| [Math.round](/docs/math/round) | 返回四舍五入后的数字。 |
| [Math.ceil](/docs/math/ceil) | 返回大于等于 value 的最小整数。 |
| [Math.floor](/docs/math/floor) | 返回小于等于 value 的最大整数。 |
| [Math.trunc](/docs/math/trunc) | 返回去掉小数部分后的数字。 |
| [Math.exp](/docs/math/exp) | 返回 e 的 value 次方。 |
| [Math.exp2](/docs/math/exp2) | 返回 2 的 value 次方。 |
| [Math.expm1](/docs/math/expm1) | 返回 exp(value) - 1。 |
| [Math.ln](/docs/math/ln) | 返回 value 的自然对数。 |
| [Math.log](/docs/math/log) | 返回以 base 为底的 value 对数。 |
| [Math.log10](/docs/math/log10) | 返回以 10 为底的 value 对数。 |
| [Math.log2](/docs/math/log2) | 返回以 2 为底的 value 对数。 |
| [Math.log1p](/docs/math/log1p) | 返回 ln(1 + value)。 |
| [Math.sin](/docs/math/sin) | 返回 value 的正弦值。 |
| [Math.cos](/docs/math/cos) | 返回 value 的余弦值。 |
| [Math.tan](/docs/math/tan) | 返回 value 的正切值。 |
| [Math.asin](/docs/math/asin) | 返回 value 的反正弦弧度。 |
| [Math.acos](/docs/math/acos) | 返回 value 的反余弦弧度。 |
| [Math.atan](/docs/math/atan) | 返回 value 的反正切弧度。 |
| [Math.atan2](/docs/math/atan2) | 根据 y 和 x 返回方向角弧度。 |
| [Math.rad](/docs/math/rad) | 返回对应弧度值。 |
| [Math.deg](/docs/math/deg) | 返回对应角度值。 |
| [Math.sinh](/docs/math/sinh) | 返回 value 的双曲正弦值。 |
| [Math.cosh](/docs/math/cosh) | 返回 value 的双曲余弦值。 |
| [Math.tanh](/docs/math/tanh) | 返回 value 的双曲正切值。 |
| [Math.asinh](/docs/math/asinh) | 返回 value 的反双曲正弦值。 |
| [Math.acosh](/docs/math/acosh) | 返回 value 的反双曲余弦值。 |
| [Math.atanh](/docs/math/atanh) | 返回 value 的反双曲正切值。 |
| [Math.random](/docs/math/random) | 返回 0 <= n < 1 的随机浮点数。 |

## 常量

| 常量 | 说明 |
| ------ | ------ |
| Math.E | 自然常数 e。 |
| Math.LN2 | 2 的自然对数。 |
| Math.LN10 | 10 的自然对数。 |
| Math.LOG2E | 以 2 为底的 e 的对数。 |
| Math.LOG10E | 以 10 为底的 e 的对数。 |
| Math.PI | 圆周率。 |
| Math.SQRT1_2 | 2 的平方根的倒数。 |
| Math.SQRT2 | 2 的平方根。 |
| Math.TAU | 圆周率的 2 倍。 |

## 示例

```bt
print Math.pow(2, 3)
print Math.sqrt(9)
print Math.PI
```

## 注意事项

- Math 是全局静态对象，不需要也不再支持使用 math() 创建对象。
- Math.min() 和 Math.max() 至少需要 1 个数字参数。
- 数字结果会尽量返回 Int；非整数、非有限值或超出 i64 范围的结果返回 Float。
