[Python-checkins] r60427 - python/branches/trunk-math/Modules/mathmodule.c
mark.dickinson
python-checkins at python.org
Tue Jan 29 21:29:16 CET 2008
Author: mark.dickinson
Date: Tue Jan 29 21:29:15 2008
New Revision: 60427
Modified:
python/branches/trunk-math/Modules/mathmodule.c
Log:
Deal with special cases (infinities, nans, zeros) directly in math_frexp
to avoid platform differences. Also fix up some error messages for
PyFPE_START_PROTECT.
Modified: python/branches/trunk-math/Modules/mathmodule.c
==============================================================================
--- python/branches/trunk-math/Modules/mathmodule.c (original)
+++ python/branches/trunk-math/Modules/mathmodule.c Tue Jan 29 21:29:15 2008
@@ -273,10 +273,16 @@
double x = PyFloat_AsDouble(arg);
if (x == -1.0 && PyErr_Occurred())
return NULL;
- errno = 0;
- PyFPE_START_PROTECT("ldexp", return 0);
- x = frexp(x, &i);
- PyFPE_END_PROTECT(x);
+ /* deal with special cases directly, to sidestep platform
+ differences */
+ if (Py_IS_NAN(x) || Py_IS_INFINITY(x) || !x) {
+ i = 0;
+ }
+ else {
+ PyFPE_START_PROTECT("in math_frexp", return 0);
+ x = frexp(x, &i);
+ PyFPE_END_PROTECT(x);
+ }
return Py_BuildValue("(di)", x, i);
}
@@ -295,7 +301,7 @@
if (! PyArg_ParseTuple(args, "di:ldexp", &x, &exp))
return NULL;
errno = 0;
- PyFPE_START_PROTECT("ldexp", return 0)
+ PyFPE_START_PROTECT("in math_ldexp", return 0)
r = ldexp(x, exp);
PyFPE_END_PROTECT(r)
if (Py_IS_FINITE(x) && Py_IS_INFINITY(r))
@@ -320,7 +326,7 @@
if (x == -1.0 && PyErr_Occurred())
return NULL;
errno = 0;
- PyFPE_START_PROTECT("ldexp", return 0);
+ PyFPE_START_PROTECT("in math_modf", return 0);
x = modf(x, &y);
PyFPE_END_PROTECT(x);
return Py_BuildValue("(dd)", x, y);
More information about the Python-checkins
mailing list