cmath – mathematical functions for complex numbers

The cmath module provides basic mathematical functions for working with complex numbers, including trigonometric, exponential, logarithmic, and conversions between rectangular (real, imag) and polar (r, phi) representations.

Functions

cmath.cos(z: complex) complex

Return the cosine of z.

cmath.exp(z: complex) complex

Return the exponential of z.

cmath.log(z: complex) complex

Return the natural logarithm of z. The branch cut is along the negative real axis.

cmath.log10(z: complex) complex

Return the base-10 logarithm of z. The branch cut is along the negative real axis.

cmath.phase(z: complex) float

Returns the phase of the number z, in the range (-pi, +pi].

cmath.polar(z: complex) Tuple[float, float]

Returns, as a tuple, the polar form of z.

cmath.rect(r: float, phi: float) complex

Returns the complex number with modulus r and phase phi.

cmath.sin(z: complex) complex

Return the sine of z.

cmath.sqrt(z: complex) complex

Return the square-root of z.

Constants

cmath.e: float

base of the natural logarithm

cmath.pi: float

the ratio of a circle’s circumference to its diameter