from test import support
import unittest
import itertools
+import decimal
import math
import os
import platform
self.assertRaises(ValueError, math.factorial, -1e100)
self.assertRaises(ValueError, math.factorial, math.pi)
+ def testFactorialNonIntegers(self):
+ self.assertRaises(TypeError, math.factorial, decimal.Decimal(5.2))
+ self.assertRaises(TypeError, math.factorial, "5")
+
# Other implementations may place different upper bounds.
@support.cpython_only
def testFactorialHugeInputs(self):
{
long x;
int overflow;
- PyObject *result, *odd_part, *two_valuation;
+ PyObject *result, *odd_part, *two_valuation, *pyint_form;
if (PyFloat_Check(arg)) {
PyObject *lx;
x = PyLong_AsLongAndOverflow(lx, &overflow);
Py_DECREF(lx);
}
- else
- x = PyLong_AsLongAndOverflow(arg, &overflow);
+ else {
+ pyint_form = PyNumber_Index(arg);
+ if (pyint_form == NULL) {
+ return NULL;
+ }
+ x = PyLong_AsLongAndOverflow(pyint_form, &overflow);
+ Py_DECREF(pyint_form);
+ }
if (x == -1 && PyErr_Occurred()) {
return NULL;