summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-07-12 11:19:45 (GMT)
committerGuido van Rossum <guido@python.org>2001-07-12 11:19:45 (GMT)
commitb82fedc7d8789f82e04ad16fc0e516224a1fd0e3 (patch)
tree7b9fc1d2cccc6300e6ef9306ba5cae0a2901732f /Objects
parente9880c81b92a4bc72c541e8d89e1872b4816baa4 (diff)
downloadcpython-b82fedc7d8789f82e04ad16fc0e516224a1fd0e3.zip
cpython-b82fedc7d8789f82e04ad16fc0e516224a1fd0e3.tar.gz
cpython-b82fedc7d8789f82e04ad16fc0e516224a1fd0e3.tar.bz2
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.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/intobject.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c
index de28156..b0ed82a 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -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);