[Python-Dev] [patch] Improvements for float and math
Christian Heimes
lists at cheimes.de
Mon Dec 17 17:15:16 CET 2007
I've implemented several small improvements for floats and the math
module. You can find a description and the patches in our bug tracker:
http://bugs.python.org/issue1635
http://bugs.python.org/issue1640
Summary:
* Full and platform independent round trip for +/-inf and nan. Before
the patch the round trip didn't work on Windows and Windows returned
different repr() for nan and inf (1.#INF and -1.#IND).
>>> 1e500
inf
>>> -1e500
-inf
>>> 1e500 * 0.
nan
>>> float("nan")
nan
>>> float("inf")
inf
>>> float("-inf")
-inf
* math.isnan() and math.isinf() functions. The Py_IS_NAN and
Py_IS_INFINITY macros now use isinf and isnan on platforms that support
the functions. Although they are C99 functions they are also available
on GNU89 (C89 + GNU extensions) and other platforms. We already use them
on Windows.
* math.sign() function
>>> math.sign(42)
1
>>> math.sign(-42)
-1
>>> math.sign(0)
0
On platforms with full IEEE 754 semantics and copysign() support:
>>> math.sign(0.0)
1
>>> math.sign(-0.0)
-1
* Py_MATH_PI and Py_MATH_E macros with long double precision for future use.
* 1st and 2nd kind Bessel functions (j0, j1. jn, y0, y1, yn), error
functions (erf, erfc) and gamma function (lgamma with sign). They are
available in most libm libraries.
Please review the patches and comment on them.
Christian
More information about the Python-Dev
mailing list