[Python-checkins] CVS: python/dist/src/Objects intobject.c,2.57,2.58

Guido van Rossum gvanrossum@users.sourceforge.net
Thu, 12 Jul 2001 04:19:47 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv4513

Modified Files:
	intobject.c 
Log Message:
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.


Index: intobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v
retrieving revision 2.57
retrieving revision 2.58
diff -C2 -r2.57 -r2.58
*** intobject.c	2001/06/18 19:21:11	2.57
--- intobject.c	2001/07/12 11:19:45	2.58
***************
*** 511,521 ****
  	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;
  	}
   	if ((PyObject *)z != Py_None) {
--- 511,519 ----
  	CONVERT_TO_LONG(w, iw);
  	if (iw < 0) {
! 		/* 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) {