# 9.2. `math` — 数学函数¶

This module is always available. It provides access to the mathematical functions defined by the C standard.

## 9.2.1. 数论与表示函数¶

`math.``ceil`(x)

Return the ceiling of x as a float, the smallest integer value greater than or equal to x.

`math.``copysign`(x, y)

Return x with the sign of y. On a platform that supports signed zeros, `copysign(1.0, -0.0)` returns -1.0.

2.6 新版功能.

`math.``fabs`(x)

`math.``factorial`(x)

Return x factorial. Raises `ValueError` if x is not integral or is negative.

2.6 新版功能.

`math.``floor`(x)

Return the floor of x as a float, the largest integer value less than or equal to x.

`math.``fmod`(x, y)

`math.``frexp`(x)

`math.``fsum`(iterable)

```>>> sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
0.9999999999999999
>>> fsum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
1.0
```

2.6 新版功能.

`math.``isinf`(x)

Check if the float x is positive or negative infinity.

2.6 新版功能.

`math.``isnan`(x)

Check if the float x is a NaN (not a number). For more information on NaNs, see the IEEE 754 standards.

2.6 新版功能.

`math.``ldexp`(x, i)

`math.``modf`(x)

`math.``trunc`(x)

Return the `Real` value x truncated to an `Integral` (usually a long integer). Uses the `__trunc__` method.

2.6 新版功能.

## 9.2.2. 幂函数与对数函数¶

`math.``exp`(x)

Return `e**x`.

`math.``expm1`(x)

Return `e**x - 1`. For small floats x, the subtraction in `exp(x) - 1` can result in a significant loss of precision; the `expm1()` function provides a way to compute this quantity to full precision:

```>>> from math import exp, expm1
>>> exp(1e-5) - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1(1e-5)    # result accurate to full precision
1.0000050000166668e-05
```

2.7 新版功能.

`math.``log`(x[, base])

`math.``log1p`(x)

2.6 新版功能.

`math.``log10`(x)

`math.``pow`(x, y)

`math.``sqrt`(x)

## 9.2.3. 三角函数¶

`math.``acos`(x)

`math.``asin`(x)

`math.``atan`(x)

`math.``atan2`(y, x)

`math.``cos`(x)

`math.``hypot`(x, y)

`math.``sin`(x)

`math.``tan`(x)

## 9.2.4. 角度转换¶

`math.``degrees`(x)

`math.``radians`(x)

## 9.2.5. 双曲函数¶

`math.``acosh`(x)

2.6 新版功能.

`math.``asinh`(x)

2.6 新版功能.

`math.``atanh`(x)

2.6 新版功能.

`math.``cosh`(x)

`math.``sinh`(x)

`math.``tanh`(x)

## 9.2.6. 特殊函数¶

`math.``erf`(x)

Return the error function at x.

2.7 新版功能.

`math.``erfc`(x)

Return the complementary error function at x.

2.7 新版功能.

`math.``gamma`(x)

Return the Gamma function at x.

2.7 新版功能.

`math.``lgamma`(x)

2.7 新版功能.

## 9.2.7. 常量¶

`math.``pi`

The mathematical constant π = 3.141592…, to available precision.

`math.``e`

The mathematical constant e = 2.718281…, to available precision.

`math` 模块主要包含围绕平台C数学库函数的简单包装器。特殊情况下的行为在适当情况下遵循C99标准的附录F。当前的实现将引发 `ValueError` 用于无效操作，如 `sqrt(-1.0)``log(0.0)` （其中C99附件F建议发出无效操作信号或被零除）， 和 `OverflowError` 用于溢出的结果（例如， `exp(1000.0)` ）。除非一个或多个输入参数是NaN，否则不会从上述任何函数返回NaN；在这种情况下，大多数函数将返回一个NaN，但是（再次遵循C99附件F）这个规则有一些例外，例如 `pow(float('nan'), 0.0)``hypot(float('nan'), float('inf'))`

`cmath` 模块