diff options
author | Guido van Rossum <guido@python.org> | 2001-07-12 11:21:17 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-07-12 11:21:17 (GMT) |
commit | 0ec9abaa2b5f85837feae5c6cbc1491f2f34f16f (patch) | |
tree | 0e887eba83a87d1afb1fad990731a7c6ea724c5a /Objects | |
parent | b82fedc7d8789f82e04ad16fc0e516224a1fd0e3 (diff) | |
download | cpython-0ec9abaa2b5f85837feae5c6cbc1491f2f34f16f.zip cpython-0ec9abaa2b5f85837feae5c6cbc1491f2f34f16f.tar.gz cpython-0ec9abaa2b5f85837feae5c6cbc1491f2f34f16f.tar.bz2 |
On long to the negative long 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/longobject.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 048b8e5..85b26a3 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -1543,14 +1543,13 @@ long_pow(PyObject *v, PyObject *w, PyObject *x) size_b = b->ob_size; if (size_b < 0) { - if (a->ob_size) - PyErr_SetString(PyExc_ValueError, - "long integer to a negative power"); - else - PyErr_SetString(PyExc_ZeroDivisionError, - "zero to a negative power"); - z = NULL; - goto error; + /* Return a float. This works because we know that + this calls float_pow() which converts its + arguments to double. */ + Py_DECREF(a); + Py_DECREF(b); + Py_DECREF(c); + return PyFloat_Type.tp_as_number->nb_power(v, w, x); } z = (PyLongObject *)PyLong_FromLong(1L); for (i = 0; i < size_b; ++i) { |