cmath Module in Python

cmath Module in Python

cmath module in Python is for performing mathematical operations on complex numbers. This module contains functions that accept integers, floating-point numbers, and complex numbers as arguments and work on them. Functions defined in this module also accept objects that have __complex__() or __float__() function which convert the object into a complex number or a floating-point number, and then functions are then applied on the converted or modified object. 

 

 

Python cmath functions

The functions and constants contained in this module are listed below:

 

Method Description
phase() This method is used to return the argument or phase of a complex number.
polar() This method returns the representation of a complex number in polar coordinates.
rect() This method returns the rectangular representation of complex numbers when complex number in polar coordinates form is used to invoke the method.
isclose() This method is used to check if two complex numbers are close to each other or not.
isfinite() This method is used to check if the argument is neither an infinity nor a NaN.
isinf() This method is used to check if the argument is a positive or a negative infinity.
isnan() This method is used to check if the argument is a NaN which stands for Not a Number.

Power and Logarithmic Functions

Function Description
exp() This function returns the exponent of e.
log() This function returns the logarithm of the specified number to the specified base.
log10() This function returns the base-10 logarithm of the specified complex number.
sqrt() This function returns the square root of the specified complex number.

Trigonometric Functions

Function Description
sin() This function is used to return the complex sine of a complex number.
cos() This function is used to return the complex cosine of a complex number.
tan() This function is used to return the complex tangent of a complex number.
asin() This function is used to return the complex arc sine of a complex number.
acos() This function is used to return the complex arc cosine of a complex number.
atan() This function is used to return the complex arc tangent of a complex number.

Hyperbolic Functions

Function Description
sinh() This function is used to return the complex hyperbolic sine of a complex number.
cosh() This function is used to return the complex hyperbolic cosine of a complex number.
tanh() This function is used to return the complex hyperbolic tangent of a complex number.
asinh() This function is used to return the complex inverse hyperbolic sine of a complex number.
acosh() This function is used to return the complex inverse hyperbolic cosine of a complex number.
atanh() This function is used to return the complex inverse hyperbolic tangent of a complex number.

Constants

Constant Description
pi This constant returns the value of 𝜋 to the available precision.
e This constant returns the value of e to the available precision.
tau This constant returns the value of Τ to the available precision.
inf This constant returns a floating-point positive infinity.
infj This constant returns a complex number with zero real part and positive infinity imaginary part.
nan This constant returns a floating-point “not a number” (NaN) value.
nanj This constant returns a complex number with zero real part and NaN imaginary part.
Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *