:mod:`cmath` --- Complex math functions ======================================= .. module:: cmath :synopsis: Complex math functions This module implements a subset of the corresponding :term:`CPython` module, as described below. For more information, please refer to the original CPython documentation: `cmath `_ This module provides functions for performing mathematical operations on complex numbers. Availability: not available on WiPy and ESP8266. This module requires floating-point support. Quick usage example:: import cmath # Complex number operations z = 1 + 2j print('z =', z) print('abs(z) =', abs(z)) print('phase(z) =', cmath.phase(z)) print('polar(z) =', cmath.polar(z)) print('rect(1, cmath.pi/2) =', cmath.rect(1, cmath.pi/2)) # Trigonometric functions print('sin(z) =', cmath.sin(z)) print('cos(z) =', cmath.cos(z)) print('tan(z) =', cmath.tan(z)) # Exponentials and logarithms print('exp(z) =', cmath.exp(z)) print('log(z) =', cmath.log(z)) print('log10(z) =', cmath.log10(z)) # Square root print('sqrt(z) =', cmath.sqrt(z)) Constants ~~~~~~~~~ .. data:: cmath.e The base of the natural logarithm, e, approximately equal to 2.718281828459045. .. data:: cmath.pi The ratio of a circle's circumference to its diameter, approximately equal to 3.141592653589793. Functions ~~~~~~~~~ .. function:: cmath.phase(x) Return the phase (argument) of a complex number, in radians, in the range (-pi, +pi]. .. function:: cmath.polar(x) Return the polar representation of a complex number, as a tuple (r, phi), where r is the modulus and phi is the phase. .. function:: cmath.rect(r, phi) Return the complex number with modulus r and phase phi. .. function:: cmath.sin(x) Return the sine of the complex number. .. function:: cmath.cos(x) Return the cosine of the complex number. .. function:: cmath.tan(x) Return the tangent of the complex number. .. function:: cmath.exp(x) Return e raised to the power of x. .. function:: cmath.log(x) Return the natural logarithm of x (base e). The branch cut is along the negative real axis. .. function:: cmath.log10(x) Return the base-10 logarithm of x. The branch cut is along the negative real axis. .. function:: cmath.sqrt(x) Return the square root of x.