]> granicus.if.org Git - python/commitdiff
On int to the negative integral power, let float handle it instead of
authorGuido van Rossum <guido@python.org>
Thu, 12 Jul 2001 11:19:45 +0000 (11:19 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 12 Jul 2001 11:19:45 +0000 (11:19 +0000)
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.

Objects/intobject.c

index de28156c06d836080a5b14c345bfbbf1244aa315..b0ed82a785e25f70a4fb185add19e14f34861675 100644 (file)
@@ -510,13 +510,11 @@ int_pow(PyIntObject *v, PyIntObject *w, PyIntObject *z)
        CONVERT_TO_LONG(v, iv);
        CONVERT_TO_LONG(w, iw);
        if (iw < 0) {
-               if (iv)
-                       PyErr_SetString(PyExc_ValueError,
-                                       "cannot raise integer to a negative power");
-               else
-                       PyErr_SetString(PyExc_ZeroDivisionError,
-                                       "cannot raise 0 to a negative power");
-               return NULL;
+               /* Return a float.  This works because we know that
+                  this calls float_pow() which converts its
+                  arguments to double. */
+               return PyFloat_Type.tp_as_number->nb_power(
+                       (PyObject *)v, (PyObject *)w, (PyObject *)z);
        }
        if ((PyObject *)z != Py_None) {
                CONVERT_TO_LONG(z, iz);