Skip to content
151 changes: 101 additions & 50 deletions Doc/library/cmath.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,57 @@ the function is then applied to the result of the conversion.
1.4142135623730951j


==================================================== ============================================
**Conversions to and from polar coordinates**
--------------------------------------------------------------------------------------------------
:func:`phase(z) <phase>` Return the phase of *z*
:func:`polar(z) <polar>` Return the representation of *z* in polar coordinates.
:func:`rect(r, phi) <rect>` Return the complex number *z* with polar coordinates *r* and *phi*

**Power and logarithmic functions**
--------------------------------------------------------------------------------------------------
:func:`exp(z) <exp>` Return *e* raised to the power *z*
:func:`log(z[, base]) <log>` Return the logarithm of *z* to the given *base* (*e* by default)
:func:`log10(z) <log10>` Return the base-10 logarithm of *z*
:func:`sqrt(z) <sqrt>` Return the square root of *z*

**Trigonometric functions**
--------------------------------------------------------------------------------------------------
:func:`acos(z) <acos>` Return the arc cosine of *z*
:func:`asin(z) <asin>` Return the arc sine of *z*
:func:`atan(z) <atan>` Return the arc tangent of *z*
:func:`cos(z) <cos>` Return the cosine of *z*.
:func:`sin(z) <sin>` Return the sine of *z*.
:func:`tan(z) <tan>` Return the tangent of *z*.

**Hyperbolic functions**
--------------------------------------------------------------------------------------------------
:func:`acosh(z) <acosh>` Return the inverse hyperbolic cosine of *z*
:func:`asinh(z) <asinh>` Return the inverse hyperbolic sine of *z*
:func:`atanh(z) <atanh>` Return the inverse hyperbolic tangent of *z*
:func:`cosh(z) <cosh>` Return the hyperbolic cosine of *z*
:func:`sinh(z) <sinh>` Return the hyperbolic sine of *z*.
:func:`tanh(z) <tanh>` Return the hyperbolic tangent of *z*.

**Classification functions**
--------------------------------------------------------------------------------------------------
:func:`isfinite(z) <isfinite>` Check if all components of *z* are finite
:func:`isinf(z) <isinf>` Check if any component of *z* is infinite
:func:`isnan(z) <isnan>` Check if any component of *z* is a NaN
:func:`isclose(a, b, *, rel_tol, abs_tol) <isclose>` Check if the values *a* and *b* are close to each other

**Constants**
--------------------------------------------------------------------------------------------------
:data:`pi` *π* = 3.141592...
:data:`e` *e* = 2.718281...
:data:`tau` *τ* = 2\ *π* = 6.283185...
:data:`inf` Positive infinity
:data:`infj` Pure imaginary infinity
:data:`nan` "Not a number" (NaN)
:data:`nanj` Pure imaginary NaN
==================================================== ============================================


Conversions to and from polar coordinates
-----------------------------------------

Expand All @@ -55,13 +106,13 @@ segment that joins the origin to *z*.
The following functions can be used to convert from the native
rectangular coordinates to polar coordinates and back.

.. function:: phase(x)
.. function:: phase(z)

Return the phase of *x* (also known as the *argument* of *x*), as a float.
``phase(x)`` is equivalent to ``math.atan2(x.imag, x.real)``. The result
Return the phase of *z* (also known as the *argument* of *z*), as a float.
``phase(z)`` is equivalent to ``math.atan2(z.imag, z.real)``. The result
lies in the range [-\ *π*, *π*], and the branch cut for this operation lies
along the negative real axis. The sign of the result is the same as the
sign of ``x.imag``, even when ``x.imag`` is zero::
sign of ``z.imag``, even when ``z.imag`` is zero::

>>> phase(-1+0j)
3.141592653589793
Expand All @@ -71,147 +122,147 @@ rectangular coordinates to polar coordinates and back.

.. note::

The modulus (absolute value) of a complex number *x* can be
The modulus (absolute value) of a complex number *z* can be
computed using the built-in :func:`abs` function. There is no
separate :mod:`cmath` module function for this operation.


.. function:: polar(x)
.. function:: polar(z)

Return the representation of *x* in polar coordinates. Returns a
pair ``(r, phi)`` where *r* is the modulus of *x* and phi is the
phase of *x*. ``polar(x)`` is equivalent to ``(abs(x),
phase(x))``.
Return the representation of *z* in polar coordinates. Returns a
pair ``(r, phi)`` where *r* is the modulus of *z* and *phi* is the
phase of *z*. ``polar(z)`` is equivalent to ``(abs(z),
phase(z))``.


.. function:: rect(r, phi)

Return the complex number *x* with polar coordinates *r* and *phi*.
Return the complex number *z* with polar coordinates *r* and *phi*.
Equivalent to ``complex(r * math.cos(phi), r * math.sin(phi))``.


Power and logarithmic functions
-------------------------------

.. function:: exp(x)
.. function:: exp(z)

Return *e* raised to the power *x*, where *e* is the base of natural
Return *e* raised to the power *z*, where *e* is the base of natural
logarithms.


.. function:: log(x[, base])
.. function:: log(z[, base])

Returns the logarithm of *x* to the given *base*. If the *base* is not
specified, returns the natural logarithm of *x*. There is one branch cut,
Return the logarithm of *z* to the given *base*. If the *base* is not
specified, returns the natural logarithm of *z*. There is one branch cut,
from 0 along the negative real axis to -∞.


.. function:: log10(x)
.. function:: log10(z)

Return the base-10 logarithm of *x*. This has the same branch cut as
Return the base-10 logarithm of *z*. This has the same branch cut as
:func:`log`.


.. function:: sqrt(x)
.. function:: sqrt(z)

Return the square root of *x*. This has the same branch cut as :func:`log`.
Return the square root of *z*. This has the same branch cut as :func:`log`.


Trigonometric functions
-----------------------

.. function:: acos(x)
.. function:: acos(z)

Return the arc cosine of *x*. There are two branch cuts: One extends right
Return the arc cosine of *z*. There are two branch cuts: One extends right
from 1 along the real axis to ∞. The other extends left from -1 along the
real axis to -∞.


.. function:: asin(x)
.. function:: asin(z)

Return the arc sine of *x*. This has the same branch cuts as :func:`acos`.
Return the arc sine of *z*. This has the same branch cuts as :func:`acos`.


.. function:: atan(x)
.. function:: atan(z)

Return the arc tangent of *x*. There are two branch cuts: One extends from
Return the arc tangent of *z*. There are two branch cuts: One extends from
``1j`` along the imaginary axis to ``∞j``. The other extends from ``-1j``
along the imaginary axis to ``-∞j``.


.. function:: cos(x)
.. function:: cos(z)

Return the cosine of *x*.
Return the cosine of *z*.


.. function:: sin(x)
.. function:: sin(z)

Return the sine of *x*.
Return the sine of *z*.


.. function:: tan(x)
.. function:: tan(z)

Return the tangent of *x*.
Return the tangent of *z*.


Hyperbolic functions
--------------------

.. function:: acosh(x)
.. function:: acosh(z)

Return the inverse hyperbolic cosine of *x*. There is one branch cut,
Return the inverse hyperbolic cosine of *z*. There is one branch cut,
extending left from 1 along the real axis to -∞.


.. function:: asinh(x)
.. function:: asinh(z)

Return the inverse hyperbolic sine of *x*. There are two branch cuts:
Return the inverse hyperbolic sine of *z*. There are two branch cuts:
One extends from ``1j`` along the imaginary axis to ``∞j``. The other
extends from ``-1j`` along the imaginary axis to ``-∞j``.


.. function:: atanh(x)
.. function:: atanh(z)

Return the inverse hyperbolic tangent of *x*. There are two branch cuts: One
Return the inverse hyperbolic tangent of *z*. There are two branch cuts: One
extends from ``1`` along the real axis to ``∞``. The other extends from
``-1`` along the real axis to ``-∞``.


.. function:: cosh(x)
.. function:: cosh(z)

Return the hyperbolic cosine of *x*.
Return the hyperbolic cosine of *z*.


.. function:: sinh(x)
.. function:: sinh(z)

Return the hyperbolic sine of *x*.
Return the hyperbolic sine of *z*.


.. function:: tanh(x)
.. function:: tanh(z)

Return the hyperbolic tangent of *x*.
Return the hyperbolic tangent of *z*.


Classification functions
------------------------

.. function:: isfinite(x)
.. function:: isfinite(z)

Return ``True`` if both the real and imaginary parts of *x* are finite, and
Return ``True`` if both the real and imaginary parts of *z* are finite, and
``False`` otherwise.

.. versionadded:: 3.2


.. function:: isinf(x)
.. function:: isinf(z)

Return ``True`` if either the real or the imaginary part of *x* is an
Return ``True`` if either the real or the imaginary part of *z* is an
infinity, and ``False`` otherwise.


.. function:: isnan(x)
.. function:: isnan(z)

Return ``True`` if either the real or the imaginary part of *x* is a NaN,
Return ``True`` if either the real or the imaginary part of *z* is a NaN,
and ``False`` otherwise.


Expand Down
Loading