diff Objects/longobject.c @ 18500:e6ecd8a07ea8 legacy-trunk

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.
author Guido van Rossum <guido@python.org>
date Thu, 12 Jul 2001 11:21:17 +0000
parents eff8da7c3dcb
children b287f2927db3
line wrap: on
line diff
--- a/Objects/longobject.c	Thu Jul 12 11:19:45 2001 +0000
+++ b/Objects/longobject.c	Thu Jul 12 11:21:17 2001 +0000
@@ -1543,14 +1543,13 @@
 	
 	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) {