mathematical functions for complex numbers

cmath – mathematical functions for complex numbers

This module implements a subset of the corresponding CPython module, as described below. For more information, refer to the original CPython documentation: cmath.

The cmath module provides some basic mathematical functions for working with complex numbers.

Functions

cmath.cos

cmath.cos(z)

Return the cosine of z.

cmath.exp

cmath.exp(z)

Return the exponential of z.

cmath.log

cmath.log(z)

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

cmath.log10

cmath.log10(z)

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

cmath.phase

cmath.phase(z)

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

cmath.polar

cmath.polar(z)

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

cmath.rect

cmath.rect(r, phi)

Returns the complex number with modulus r and phase phi.

cmath.sin

cmath.sin(z)

Return the sine of z.

cmath.sqrt

cmath.sqrt(z)

Return the square-root of z.

Constants

cmath.e

cmath.e

base of the natural logarithm

cmath.pi

cmath.pi

the ratio of a circle’s circumference to its diameter

On this page

cmath – mathematical functions for complex numbers