| 常量 | 说明 |
|---|---|
| math.pi) | 圆周率 \(\pi = 3.141592...\) |
| math.e) | 自然常数 \(e = 2.718281...\) |
| math.tau) | 常数 \(\tau = 2\pi = 6.283185...\) |
| math.inf) | 正无穷 \(+\infty\) |
| math.nan) | 非数值(Not A Number) |
| 数论函数 | 说明 |
|---|---|
| math.comb) | 求全组合(不重复且无顺序地从 n 项中选择 k 项组合的方式总数) |
| math.factorial) | 求 n 的阶乘 |
| math.gcd) | 求最大公约数 |
| math.isqrt) | 求整数平方根(向下取整) |
| math.lcm) | 求最小公倍数 |
| math.perm) | 求全排列(无重复且有顺序地从 n 项中选择 k 项排列的方式总数) |
| 浮点算数函数 | 说明 |
|---|---|
| math.ceil) | 向上取整(即大于等于 x 的最小整数 \(\lceil x \rceil\)) |
| math.fabs) | 绝对值(\(\vert x \vert\)) |
| math.floor) | 向下取整(即小于等于 x 的最大整数 \(\lfloor x \rfloor\)) |
| math.fma) | 快速乘加运算(\((x * y) + z\)) |
| math.fmod) | 除法取余数(\(x \% y\)) |
| math.modf) | 分解整数和小数部分 |
| math.remainder) | 除法取余数(四舍六入五取偶 \(x − round(x/y) * y\)) |
| 浮点操作函数 | 说明 |
|---|---|
| math.copysign) | 复制符号位 |
| math.frexp) | 获取浮点数的尾数和指数 |
| math.isclose) | 判断两个浮点数是否接近 |
| math.isfinite) | 判断一个浮点数是有限(不是无穷大,也不是 NaN) |
| math.isinf) | 判断一个浮点数是无穷大(正负无穷) |
| math.isnan) | 判断一个浮点数是 NaN(Not A Number) |
| math.ldexp) | 由尾数和指数计算出浮点数值(\(x \times 2 ^ i\)) |
| math.nextafter) | 获取下一个浮点数值 |
| math.ulp) | 获取浮点数的最小有效比特位的值(Unit in the Last Place) |
| 幂函数、指数函数和对数函数 | 说明 |
|---|---|
| math.cbrt) | 求立方根(\(\sqrt[3]{x}\)) |
| math.exp) | 自然常数 e 的幂(\(e^x\)) |
| math.exp2) | 2 的幂(\(2^x\)) |
| math.expm1) | 自然常数 e 的幂减 1(\(e^x - 1\)) |
| math.log) | 对数函数(\(log_n(x)\),默认底数为 e) |
| math.log1p) | 以 e 为底,值加 1 的对数函数(\(log_e(x+1)\)) |
| math.log1p) | 以 e 为底,值加 1 的对数函数(\(log_e(x+1)\)) |
| math.log2) | 以 2 为底的对数函数(\(log_2(x)\)) |
| math.log10) | 以 10 为底的对数函数(\(log_{10}(x)\)) |
| math.pow) | 幂指函数(\(x^y\)) |
| math.sqrt) | 求平方根(\(\sqrt{x}\)) |
| 加总和乘积函数 | 说明 |
|---|---|
| math.dist) | 两点间的欧氏距离(\(\sqrt{\sum_{i=1}^{n}(x_i-y_i)^2}\)) |
| math.fsum) | 浮点数求和(\(\sum_{i=1}^{n}(x_i)\)) |
| math.hypot) | 欧几里得范数(\(\|x\|_2 = \sqrt{\sum_{i=1}^{n}(x_i)}\)) |
| math.prod) | 连续相乘的积(\(\prod_{i=1}^{n} x_i\)) |
| math.sumprod) | 两个可迭代对象元素乘积的总和(\(\sum_{i=1}^{n} (x_i \times y_i)\)) |
| 角度和弧度转换函数 | 说明 |
|---|---|
| math.degrees) | 将弧度转换为角度(\(degrees = radians \times \frac{180}{\pi}\)) |
| math.radians) | 将角度转换为弧度(\(radians = degrees \times \frac{\pi}{180}\)) |
| 三角函数 | 说明 |
|---|---|
| math.acos) | 反余弦函数 |
| math.asin) | 反正弦函数 |
| math.atan) | 反正切函数 |
| math.atan2) | 反正切函数 |
| math.cos) | 余弦函数 |
| math.sin) | 正弦函数 |
| math.tan) | 正切函数 |
| 双曲函数 | 说明 |
|---|---|
| math.acosh) | 反双曲余弦函数 |
| math.asinh) | 反双曲正弦函数 |
| math.atanh) | 反双曲正切函数 |
| math.cosh) | 双曲余弦函数 |
| math.sinh) | 双曲正弦函数 |
| math.tanh) | 双曲正切函数 |
| 特殊函数 | 说明 |
|---|---|
| math.erf) | 高斯误差函数(\(\mathrm{erf}(x) = \frac{2}{\sqrt{\pi}} \int_0^x e^{-t^2} \, dt\)) |
| math.erfc) | 互补误差函数 (\(\mathrm{erfc}(x) = 1 - \mathrm{erf}(x)\)) |
| math.gamma) | 伽马函数(\(\Gamma(z) = \int_0^\infty t^{z-1} e^{-t} \, dt\)) |
| math.lgamma) | 伽马函数 绝对值的自然对数(\(\mathrm{lgamma}(x) = \ln{\vert\Gamma(x)\vert}\)) |