summaryrefslogtreecommitdiffstats
path: root/Modules/mathmodule.c
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-12-20 14:07:47 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2009-12-20 14:07:47 (GMT)
commitda39dbffb625b3c527d18de31a2a7bcbc7d1679c (patch)
tree7b547e437c1378b1db57917ff56b80ccb6984a3e /Modules/mathmodule.c
parenta8f6f1e2d63b90549278b1162d264bb279459007 (diff)
downloadcpython-da39dbffb625b3c527d18de31a2a7bcbc7d1679c.zip
cpython-da39dbffb625b3c527d18de31a2a7bcbc7d1679c.tar.gz
cpython-da39dbffb625b3c527d18de31a2a7bcbc7d1679c.tar.bz2
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. ........
Diffstat (limited to 'Modules/mathmodule.c')
-rw-r--r--Modules/mathmodule.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index f835005..92f5f42 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -1137,15 +1137,22 @@ math_factorial(PyObject *self, PyObject *arg)
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) {