[Python-checkins] r76917 - in python/branches/py3k: Modules/mathmodule.c
mark.dickinson
python-checkins at python.org
Sun Dec 20 15:07:48 CET 2009
Author: mark.dickinson
Date: Sun Dec 20 15:07:47 2009
New Revision: 76917
Log:
Merged revisions 76916 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76916 | mark.dickinson | 2009-12-20 13:58:18 +0000 (Sun, 20 Dec 2009) | 3 lines
math.factorial depends on PyLong_AsLong correctly converting floats; rewrite
it to do the conversion explicitly instead. See issue #7550.
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Modules/mathmodule.c
Modified: python/branches/py3k/Modules/mathmodule.c
==============================================================================
--- python/branches/py3k/Modules/mathmodule.c (original)
+++ python/branches/py3k/Modules/mathmodule.c Sun Dec 20 15:07:47 2009
@@ -1137,15 +1137,22 @@
PyObject *result, *iobj, *newresult;
if (PyFloat_Check(arg)) {
+ PyObject *lx;
double dx = PyFloat_AS_DOUBLE((PyFloatObject *)arg);
- if (dx != floor(dx)) {
+ if (!(Py_IS_FINITE(dx) && dx == floor(dx))) {
PyErr_SetString(PyExc_ValueError,
"factorial() only accepts integral values");
return NULL;
}
+ lx = PyLong_FromDouble(dx);
+ if (lx == NULL)
+ return NULL;
+ x = PyLong_AsLong(lx);
+ Py_DECREF(lx);
}
+ else
+ x = PyLong_AsLong(arg);
- x = PyLong_AsLong(arg);
if (x == -1 && PyErr_Occurred())
return NULL;
if (x < 0) {
More information about the Python-checkins
mailing list