Move description of math module changes; various edits to description of cmath changes

This commit is contained in:
Andrew M. Kuchling 2008-04-20 16:54:02 +00:00
parent 98c317a34d
commit 2cede399ec
1 changed files with 62 additions and 48 deletions

View File

@ -1292,11 +1292,42 @@ Here are all of the changes that Python 2.6 makes to the core Python language.
:func:`isnan`, return true if their floating-point argument is :func:`isnan`, return true if their floating-point argument is
infinite or Not A Number. (:issue:`1640`) infinite or Not A Number. (:issue:`1640`)
The ``math.copysign(x, y)`` function * The :mod:`math` module has seven new functions, and the existing
copies the sign bit of an IEEE 754 number, returning the absolute functions have been improved to give more consistent behaviour
value of *x* combined with the sign bit of *y*. For example, across platforms, especially with respect to handling of
``math.copysign(1, -0.0)`` returns -1.0. (Contributed by Christian floating-point exceptions and IEEE 754 special values.
Heimes.) The new functions are:
* :func:`isinf` and :func:`isnan` determine whether a given float is
a (positive or negative) infinity or a NaN (Not a Number),
respectively.
* ``copysign(x, y)`` copies the sign bit of an IEEE 754 number,
returning the absolute value of *x* combined with the sign bit of
*y*. For example, ``math.copysign(1, -0.0)`` returns -1.0.
(Contributed by Christian Heimes.)
* The inverse hyperbolic functions :func:`acosh`, :func:`asinh` and
:func:`atanh`.
* The function :func:`log1p`, returning the natural logarithm of
*1+x* (base *e*).
There's also a new :func:`trunc` function as a result of the
backport of `PEP 3141's type hierarchy for numbers <#pep-3141>`__.
The existing math functions have been modified to follow the
recommendations of the C99 standard with respect to special values
whenever possible. For example, ``sqrt(-1.)`` should now give a
:exc:`ValueError` across (nearly) all platforms, while
``sqrt(float('NaN'))`` should return a NaN on all IEEE 754
platforms. Where Annex 'F' of the C99 standard recommends signaling
'divide-by-zero' or 'invalid', Python will raise :exc:`ValueError`.
Where Annex 'F' of the C99 standard recommends signaling 'overflow',
Python will raise :exc:`OverflowError`. (See :issue:`711019`,
:issue:`1640`.)
(Contributed by Christian Heimes and Mark Dickinson.)
* Changes to the :class:`Exception` interface * Changes to the :class:`Exception` interface
as dictated by :pep:`352` continue to be made. For 2.6, as dictated by :pep:`352` continue to be made. For 2.6,
@ -1415,33 +1446,40 @@ complete list of changes, or look through the CVS logs for all the details.
available, instead of restricting itself to protocol 1. available, instead of restricting itself to protocol 1.
(Contributed by W. Barnes; :issue:`1551443`.) (Contributed by W. Barnes; :issue:`1551443`.)
* The :mod:`cmath` module has gained five new functions: :func:`polar` * The :mod:`cmath` module underwent an extensive set of revisions,
converts a complex number to polar form, returning the modulus and thanks to Mark Dickinson and Christian Heimes, that added some new
argument of that complex number. :func:`rect` does the opposite, features and greatly improved the accuracy of the computations.
turning a (modulus, argument) pair back into the corresponding
complex number. :func:`phase` returns the phase or argument of a
complex number. :func:`isnan` returns True if either the real or
imaginary part of its argument is a NaN. :func:`isinf` returns True
if either the real or imaginary part of its argument is infinite.
The :mod:`cmath` module is no longer numerically unsound. (See Five new functions were added:
:issue:`1381`): for all functions, the real and imaginary parts of
the results are accurate to within a few ulps, whenever possible.
The branch cuts for :func:`asinh`, :func:`atanh`: and :func:`atan` * :func:`polar` converts a complex number to polar form, returning
have been corrected. the modulus and argument of that complex number.
The tests for the :mod:`cmath` module have been greatly expanded. A * :func:`rect` does the opposite, turning a (modulus, argument) pair
set of nearly 2000 new testcases provides tests for the algebraic back into the corresponding complex number.
functions.
* :func:`phase` returns the phase or argument of a complex number.
* :func:`isnan` returns True if either
the real or imaginary part of its argument is a NaN.
* :func:`isinf` returns True if either the real or imaginary part of
its argument is infinite.
The revisions also improved the numerical soundness of the
:mod:`cmath` module. For all functions, the real and imaginary
parts of the results are accurate to within a few units of least
precision (ulps) whenever possible. See :issue:`1381` for the
details. The branch cuts for :func:`asinh`, :func:`atanh`: and
:func:`atan` have also been corrected.
The tests for the module have been greatly expanded; nearly 2000 new
test cases exercise the algebraic functions.
On IEEE 754 platforms, the :mod:`cmath` module now handles IEEE 754 On IEEE 754 platforms, the :mod:`cmath` module now handles IEEE 754
special values and floating-point exceptions in a manner consistent special values and floating-point exceptions in a manner consistent
with Annex 'G' of the C99 standard. with Annex 'G' of the C99 standard.
(Updates to :mod:`cmath` contributed by Mark Dickinson and Christian
Heimes.)
* A new data type in the :mod:`collections` module: :class:`namedtuple(typename, * A new data type in the :mod:`collections` module: :class:`namedtuple(typename,
fieldnames)` is a factory function that creates subclasses of the standard tuple fieldnames)` is a factory function that creates subclasses of the standard tuple
whose fields are accessible by name as well as index. For example:: whose fields are accessible by name as well as index. For example::
@ -1678,30 +1716,6 @@ complete list of changes, or look through the CVS logs for all the details.
:func:`macostools.touched` function to be removed because it depended on the :func:`macostools.touched` function to be removed because it depended on the
:mod:`macfs` module. (:issue:`1490190`) :mod:`macfs` module. (:issue:`1490190`)
* The :mod:`math` module has seven new functions, and the existing
functions have been improved to give more consistent behaviour
across platforms, especially with respect to handling of
floating-point exceptions and IEEE 754 special values.
The new functions are: :func:`isinf` and :func:`isnan`, which
determine whether a given float is a (positive or negative) infinity
or a NaN (Not a Number), respectively; :func:`copysign`; the inverse
hyperbolic functions :func:`acosh`, :func:`asinh` and :func:`atanh`;
and the function :func:`log1p`. (There's also a new function
:func:`trunc` as a result of the backport of PEP 3141; see above.)
The existing math functions have been modified to follow the
recommendations of the C99 standard with respect to special values
whenever possible. For example, sqrt(-1.) should now give a
ValueError across (nearly) all platforms, while sqrt(float('NaN'))
should return a NaN on all IEEE 754 platforms. Where Annex 'F' of
the C99 standard recommends signaling 'divide-by-zero' or 'invalid',
Python will raise ValueError. Where Annex 'F' of the C99 standard
recommends signaling 'overflow', Python will raise OverflowError.
(See :issue:`711019`, :issue:`1640`.)
(Contributed by Christian Heimes and Mark Dickinson.)
* :class:`mmap` objects now have a :meth:`rfind` method that finds * :class:`mmap` objects now have a :meth:`rfind` method that finds
a substring, beginning at the end of the string and searching a substring, beginning at the end of the string and searching
backwards. The :meth:`find` method backwards. The :meth:`find` method