Python - cmath Module



The Python cmath module provides access to the complex mathematical functions. The functions within this module accepts integers, floating points or complex numbers as arguments and converts them into a complex or floating point numbers.

A Python Polar coordinates, gives an alternative way to represent a complex number z. Where, z is stored internally using Cartesian coordinates. This is completely determined by its real part and its imaginary part.

Importing cmath Module

Before using any function of the cmath module, we need to import it by using the following command −

import cmath

Power and Logarithmic Functions in cmath Module

Python includes following power and logarithmic functions in cmath module −

S.No Function & Description
1

cmath.exp(x)

This function returns e raised to the power x, where e is the base of natural logarithms.

2

cmath.log(x[,base])

This function returns the logarithm of x to the given base.If base is not specified,returns the natural logarithm of x.

3

cmath.log10(x)

This function returns the base-10 logarithm of x . This has the same branch cut as log().

4

cmath.sqrt(x)

This function returns the square root of x. This has the same branch cut as log().

Trigonometric Functions in cmath Module

Python includes following functions that perform trigonometric calculations in the cmath module −

S.No Function & Description
1

cmath.acos(x)

This function returns the arc cosine of x .Where in this function values extent from (1,) or (-1,-).

2

cmath.asin(x)

This function returns the arc sine of x. This is similar to acos().

3

cmath.atan(x)

This function rReturns the tangent of x .Where in this function values extent from (1j,j) or (-1,-j).

4

cmath.acosh(x)

This function returns the inverse hyperbolic cosine of the given value.

5

cmath.asinh(x)

This function returns the inverse hyperbolic sine of given number.

6

cmath.atanh(x)

This function returns the inverse hyperbolic tangent of a number.

7

cmath.cosh(x)

This function returns the hyperbolic cosine of x.

8

cmath.sinh(x)

This function returns the hyperbolic sine of x.

9

cmath.tanh(x)

This function returns the hyperbolic tangent of x.

Classification Functions

Python includes following theoretic representation function in the cmath module −

S.No Function & Description
1

cmath.isfinite(x)

This function returns True if both the real and imaginary parts of x are finite; otherwise return False.

2

cmath.isinf(x)

This function returns True if either the real or the imaginary part of x i an infinity; otherwise False.

3

cmath.isnan(x)

This function returns True if both the real or the imaginary part of x is a NaN; otherwise False.

4

cmath.isclose(x)

This function returns True if the values a and b are close to each other otherwise False.

Constants

The Python cmath module defines the following mathematical constant −

S.No Function & Description
1

cmath.pi

The mathematical constant , as a float.

2

cmath.e

The mathematical constant e,as a float.

3

cmath.inf

Floating point positive infinity. Equivalent to float.

4

cmath.nan

Floating point is not a number(NaN) value. This is Equivalent to float('nan').

5

cmath.nanj

This function returns the complex number with zero real part and NaN imaginary part. Equivalent to complex (0.0, float('nan')).

6

cmath.tau

The mathematical constant , as a float.

Advertisements