This is the documentation for the latest development branch of MicroPython and may refer to features that are not available in released versions.

If you are looking for the documentation for a specific release, use the drop-down menu on the left and select the desired version.

cmath – Mathematical functions for complex numbers.

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.

Availability: not available on WiPy and ESP8266. Floating point support required for this module.

Attributes

e

base of the natural logarithm

pi

the ratio of a circle's circumference to its diameter

Functions

cos(→ float)

Return the cosine of z.

exp(→ float)

Return the exponential of z.

log(→ float)

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

log10(→ float)

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

phase(→ float)

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

polar(→ Tuple)

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

rect(→ float)

Returns the complex number with modulus r and phase phi.

sin(→ float)

Return the sine of z.

sqrt(→ _typeshed.Incomplete)

Return the square-root of z.

Module Contents

cmath.cos(z) float

Return the cosine of z.

cmath.exp(z) float

Return the exponential of z.

cmath.log(z) float

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

cmath.log10(z) float

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

cmath.phase(z) float

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

cmath.polar(z) Tuple

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

cmath.rect(r, phi) float

Returns the complex number with modulus r and phase phi.

cmath.sin(z) float

Return the sine of z.

cmath.sqrt(z) Incomplete

Return the square-root of z.

cmath.e: float

base of the natural logarithm

cmath.pi: float

the ratio of a circle’s circumference to its diameter