[Python-checkins] CVS: python/dist/src/Objects floatobject.c,2.90,2.91 intobject.c,2.68,2.69 longobject.c,1.95,1.96

Tim Peters tim_one@users.sourceforge.net
Mon, 03 Sep 2001 01:35:43 -0700


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

Modified Files:
	floatobject.c intobject.c longobject.c 
Log Message:
New restriction on pow(x, y, z):  If z is not None, x and y must be of
integer types, and y must be >= 0.  See discussion at
http://sf.net/tracker/index.php?func=detail&aid=457066&group_id=5470&atid=105470


Index: floatobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/floatobject.c,v
retrieving revision 2.90
retrieving revision 2.91
diff -C2 -d -r2.90 -r2.91
*** floatobject.c	2001/08/31 17:40:15	2.90
--- floatobject.c	2001/09/03 08:35:41	2.91
***************
*** 493,501 ****
  {
  	double iv, iw, ix;
!  /* XXX Doesn't handle overflows if z!=None yet; it may never do so :(
!   * The z parameter is really only going to be useful for integers and
!   * long integers.  Maybe something clever with logarithms could be done.
!   * [AMK]
!   */
  	CONVERT_TO_DOUBLE(v, iv);
  	CONVERT_TO_DOUBLE(w, iw);
--- 493,503 ----
  {
  	double iv, iw, ix;
! 
! 	if ((PyObject *)z != Py_None) {
! 		PyErr_SetString(PyExc_TypeError,
! 			"3rd argument to floating pow() must be None");
! 		return NULL;
! 	}
! 
  	CONVERT_TO_DOUBLE(v, iv);
  	CONVERT_TO_DOUBLE(w, iw);
***************
*** 538,551 ****
  		PyErr_SetFromErrno(PyExc_OverflowError);
  		return NULL;
- 	}
- 	if ((PyObject *)z != Py_None) {
- 		double iz;
- 		CONVERT_TO_DOUBLE(z, iz);
- 		PyFPE_START_PROTECT("pow", return 0)
- 	 	ix = fmod(ix, iz);	/* XXX To Be Rewritten */
- 	 	if (ix != 0 && ((iv < 0 && iz > 0) || (iv > 0 && iz < 0) )) {
- 		     ix += iz;
- 		}
-   		PyFPE_END_PROTECT(ix)
  	}
  	return PyFloat_FromDouble(ix);
--- 540,543 ----

Index: intobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v
retrieving revision 2.68
retrieving revision 2.69
diff -C2 -d -r2.68 -r2.69
*** intobject.c	2001/08/31 17:40:15	2.68
--- intobject.c	2001/09/03 08:35:41	2.69
***************
*** 576,579 ****
--- 576,584 ----
  	CONVERT_TO_LONG(w, iw);
  	if (iw < 0) {
+ 		if ((PyObject *)z != Py_None) {
+ 			PyErr_SetString(PyExc_TypeError, "integer pow() arg "
+ 			     "3 must not be specified when arg 2 is < 0");
+ 			return NULL;
+ 		}
  		/* Return a float.  This works because we know that
  		   this calls float_pow() which converts its

Index: longobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/longobject.c,v
retrieving revision 1.95
retrieving revision 1.96
diff -C2 -d -r1.95 -r1.96
*** longobject.c	2001/08/31 17:40:15	1.95
--- longobject.c	2001/09/03 08:35:41	1.96
***************
*** 1599,1608 ****
  	size_b = b->ob_size;
  	if (size_b < 0) {
- 		/* 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);
  	}
--- 1599,1613 ----
  	size_b = b->ob_size;
  	if (size_b < 0) {
  		Py_DECREF(a);
  		Py_DECREF(b);
  		Py_DECREF(c);
+ 		if (x != Py_None) {
+ 			PyErr_SetString(PyExc_TypeError, "integer pow() arg "
+ 			     "3 must not be specified when arg 2 is < 0");
+ 			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(v, w, x);
  	}