# 9.3. `cmath` ——关于复数的数学函数¶

This module is always available. It provides access to mathematical functions for complex numbers. The functions in this module accept integers, floating-point numbers or complex numbers as arguments. They will also accept any Python object that has either a `__complex__()` or a `__float__()` method: these methods are used to convert the object to a complex or floating-point number, respectively, and the function is then applied to the result of the conversion.

## 9.3.1. 到极坐标和从极坐标的转换¶

```z == z.real + z.imag*1j
```

`cmath.``phase`(x)

Return the phase of x (also known as the argument of x), as a float. `phase(x)` is equivalent to ```math.atan2(x.imag, x.real)```. The result lies in the range [-π, π], and the branch cut for this operation lies along the negative real axis, continuous from above. On systems with support for signed zeros (which includes most systems in current use), this means that the sign of the result is the same as the sign of `x.imag`, even when `x.imag` is zero:

```>>> phase(complex(-1.0, 0.0))
3.1415926535897931
>>> phase(complex(-1.0, -0.0))
-3.1415926535897931
```

2.6 新版功能.

`cmath.``polar`(x)

2.6 新版功能.

`cmath.``rect`(r, phi)

2.6 新版功能.

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

`cmath.``exp`(x)

Return the exponential value `e**x`.

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

`cmath.``log10`(x)

`cmath.``sqrt`(x)

## 9.3.3. 三角函数¶

`cmath.``acos`(x)

`cmath.``asin`(x)

`cmath.``atan`(x)

`cmath.``cos`(x)

`cmath.``sin`(x)

`cmath.``tan`(x)

## 9.3.4. 双曲函数¶

`cmath.``acosh`(x)

`cmath.``asinh`(x)

`cmath.``atanh`(x)

`cmath.``cosh`(x)

`cmath.``sinh`(x)

`cmath.``tanh`(x)

## 9.3.5. 分类函数¶

`cmath.``isinf`(x)

Return `True` if the real or the imaginary part of x is positive or negative infinity.

2.6 新版功能.

`cmath.``isnan`(x)

Return `True` if the real or imaginary part of x is not a number (NaN).

2.6 新版功能.

## 9.3.6. 常量¶

`cmath.``pi`

`cmath.``e`

Kahan, W: Branch cuts for complex elementary functions; or, Much ado about nothing’s sign bit. In Iserles, A., and Powell, M. (eds.), The state of the art in numerical analysis. Clarendon Press (1987) pp165–211.