Commit b82fedc7 authored by Guido van Rossum's avatar Guido van Rossum

On int to the negative integral power, let float handle it instead of

raising an error.  This was one of the two issues that the VPython
folks were particularly problematic for their students.  (The other
one was integer division...)  This implements (my) SF patch #440487.
parent e9880c81
...@@ -510,13 +510,11 @@ int_pow(PyIntObject *v, PyIntObject *w, PyIntObject *z) ...@@ -510,13 +510,11 @@ int_pow(PyIntObject *v, PyIntObject *w, PyIntObject *z)
CONVERT_TO_LONG(v, iv); CONVERT_TO_LONG(v, iv);
CONVERT_TO_LONG(w, iw); CONVERT_TO_LONG(w, iw);
if (iw < 0) { if (iw < 0) {
if (iv) /* Return a float. This works because we know that
PyErr_SetString(PyExc_ValueError, this calls float_pow() which converts its
"cannot raise integer to a negative power"); arguments to double. */
else return PyFloat_Type.tp_as_number->nb_power(
PyErr_SetString(PyExc_ZeroDivisionError, (PyObject *)v, (PyObject *)w, (PyObject *)z);
"cannot raise 0 to a negative power");
return NULL;
} }
if ((PyObject *)z != Py_None) { if ((PyObject *)z != Py_None) {
CONVERT_TO_LONG(z, iz); CONVERT_TO_LONG(z, iz);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment