Merged revisions 62380,62382-62383 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r62380 | christian.heimes | 2008-04-19 01:13:07 +0200 (Sat, 19 Apr 2008) | 3 lines

  I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.

  The patch also adds acosh, asinh, atanh, log1p and copysign to all platforms. Finally it fixes differences between platforms like different results or exceptions for edge cases. Have fun :)
........
  r62382 | christian.heimes | 2008-04-19 01:40:40 +0200 (Sat, 19 Apr 2008) | 2 lines

  Added new files to Windows project files
  More Windows related fixes are coming soon
........
  r62383 | christian.heimes | 2008-04-19 01:49:11 +0200 (Sat, 19 Apr 2008) | 1 line

  Stupid me. Py_RETURN_NAN should actually return something ...
........
This commit is contained in:
Christian Heimes 2008-04-19 00:31:39 +00:00
parent dc3e06ce3a
commit 53876d9cd8
27 changed files with 5101 additions and 1167 deletions

View file

@ -14,8 +14,81 @@ 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 are:
.. note::
On platforms with hardware and system-level support for signed
zeros, functions involving branch cuts are continuous on *both*
sides of the branch cut: the sign of the zero distinguishes one
side of the branch cut from the other. On platforms that do not
support signed zeros the continuity is as specified below.
Complex coordinates
-------------------
Complex numbers can be expressed by two important coordinate systems.
Python's :class:`complex` type uses rectangular coordinates where a number
on the complex plain is defined by two floats, the real part and the imaginary
part.
Definition::
z = x + 1j * y
x := real(z)
y := imag(z)
In engineering the polar coordinate system is popular for complex numbers. In
polar coordinates a complex number is defined by the radius *r* and the phase
angle *φ*. The radius *r* is the absolute value of the complex, which can be
viewed as distance from (0, 0). The radius *r* is always 0 or a positive float.
The phase angle *φ* is the counter clockwise angle from the positive x axis,
e.g. *1* has the angle *0*, *1j* has the angle *π/2* and *-1* the angle *-π*.
.. note::
While :func:`phase` and func:`polar` return *+π* for a negative real they
may return *-π* for a complex with a very small negative imaginary
part, e.g. *-1-1E-300j*.
Definition::
z = r * exp(1j * φ)
z = r * cis(φ)
r := abs(z) := sqrt(real(z)**2 + imag(z)**2)
phi := phase(z) := atan2(imag(z), real(z))
cis(φ) := cos(φ) + 1j * sin(φ)
.. function:: phase(x)
Return phase, also known as the argument, of a complex.
.. versionadded:: 2.6
.. function:: polar(x)
Convert a :class:`complex` from rectangular coordinates to polar
coordinates. The function returns a tuple with the two elements
*r* and *phi*. *r* is the distance from 0 and *phi* the phase
angle.
.. versionadded:: 2.6
.. function:: rect(r, phi)
Convert from polar coordinates to rectangular coordinates and return
a :class:`complex`.
.. versionadded:: 2.6
cmath functions
---------------
.. function:: acos(x)
@ -37,30 +110,35 @@ The functions are:
.. function:: asinh(x)
Return the hyperbolic arc sine of *x*. There are two branch cuts, extending
left from ``±1j`` to ``±∞j``, both continuous from above. These branch cuts
should be considered a bug to be corrected in a future release. The correct
branch cuts should extend along the imaginary axis, one from ``1j`` up to
``∞j`` and continuous from the right, and one from ``-1j`` down to ``-∞j``
and continuous from the left.
Return the hyperbolic arc sine of *x*. There are two branch cuts:
One extends from ``1j`` along the imaginary axis to ``∞j``,
continuous from the right. The other extends from ``-1j`` along
the imaginary axis to ``-∞j``, continuous from the left.
.. versionchanged:: 2.6
branch cuts moved to match those recommended by the C99 standard
.. function:: atan(x)
Return the arc tangent of *x*. There are two branch cuts: One extends from
``1j`` along the imaginary axis to ``∞j``, continuous from the left. The
``1j`` along the imaginary axis to ``∞j``, continuous from the right. The
other extends from ``-1j`` along the imaginary axis to ``-∞j``, continuous
from the left. (This should probably be changed so the upper cut becomes
continuous from the other side.)
from the left.
.. versionchanged:: 2.6
direction of continuity of upper cut reversed
.. function:: atanh(x)
Return the hyperbolic arc tangent of *x*. There are two branch cuts: One
extends from ``1`` along the real axis to ````, continuous from above. The
extends from ``1`` along the real axis to ````, continuous from below. The
other extends from ``-1`` along the real axis to ``-∞``, continuous from
above. (This should probably be changed so the right cut becomes continuous
from the other side.)
above.
.. versionchanged:: 2.6
direction of continuity of right cut reversed
.. function:: cos(x)
@ -78,6 +156,21 @@ The functions are:
Return the exponential value ``e**x``.
.. function:: isinf(x)
Return *True* if the real or the imaginary part of x is positive
or negative infinity.
.. versionadded:: 2.6
.. function:: isnan(x)
Return *True* if the real or imaginary part of x is not a number (NaN).
.. versionadded:: 2.6
.. function:: log(x[, base])
Returns the logarithm of *x* to the given *base*. If the *base* is not
@ -151,3 +244,4 @@ cuts for numerical purposes, a good reference should be the following:
nothing's sign bit. In Iserles, A., and Powell, M. (eds.), The state of the art
in numerical analysis. Clarendon Press (1987) pp165-211.