The Python has a cmath module which contains number of mathematical functions for complex numbers. The functions in this module accept integers, floating-point numbers or complex numbers as arguments. It also accept any Python object that has either a __complex__() or a __float__() method: these methods are used to convert the object to a complex or floating-point number, respectively, and the function is then applied to the result of the conversion.
The functions and constants of cmath module are listed below:
Method | Description |
phase() | Return the argument of a complex number. |
polar() | Return the representation of a complex number in polar coordinates. |
rect() | Convert a complex number from polar coordinates to rectangular coordinates. |
isclose() | Check if two values are close to each other. |
isfinite() | Check if the argument is neither an infinity nor a NaN. |
isinf() | Check if the argument is positive or negative infinity. |
isnan() | Check if the argument is a NaN (not a number). |
Functions | Description |
exp() | Returns the exponent of e. |
log() | Returns the logarithm of a given number to the given base. |
log10() | Returns the base-10 logarithm of a given complex number. |
sqrt() | Returns the square root of the given complex number. |
Functions | Description |
sin() | Returns the complex sine of a complex number. |
cos() | Returns the complex cosine of a complex number. |
tan() | Returns the complex tangent of a complex number. |
asin() | Returns the complex arc sine of a complex number. |
acos() | Returns the complex arc cosine of a complex number. |
atan() | Returns the complex arc tangent of a complex number. |
Functions | Description |
sinh() | Returns the complex hyperbolic sine of a complex number. |
cosh() | Returns the complex hyperbolic cosine of a complex number. |
tanh() | Returns the complex hyperbolic tangent of a complex number. |
asinh() | Returns the complex inverse hyperbolic sine of a complex number. |
acosh() | Returns the complex inverse hyperbolic cosine of a complex number. |
atanh() | Returns the complex inverse hyperbolic tangent of a complex number. |
Functions | Description |
pi | Returns the value of 𝜋 to the available precision. |
e | Returns the value of e to the available precision. |
tau | Returns the value of Τ to the available precision. |
inf | Returns a floating-point positive infinity. |
infj | Returns a complex number with zero real part and positive infinity imaginary part. |
nan | Returns a floating-point "not a number" (NaN) value. |
nanj | Returns a complex number with zero real part and NaN imaginary part. |