summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-09-03 08:35:41 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-09-03 08:35:41 (GMT)
commit32f453eaa476c78376cd721d29ba8ab726e400bb (patch)
treeaec8b2e54ec4a0a7cbd66569d3a8531db118f153 /Objects
parent5d2b77cf31c5a3cbabc74936831480b9caea3a12 (diff)
downloadcpython-32f453eaa476c78376cd721d29ba8ab726e400bb.zip
cpython-32f453eaa476c78376cd721d29ba8ab726e400bb.tar.gz
cpython-32f453eaa476c78376cd721d29ba8ab726e400bb.tar.bz2
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
Diffstat (limited to 'Objects')
-rw-r--r--Objects/floatobject.c22
-rw-r--r--Objects/intobject.c5
-rw-r--r--Objects/longobject.c11
3 files changed, 20 insertions, 18 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 39eba8e..8cd26b4 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -492,11 +492,13 @@ static PyObject *
float_pow(PyObject *v, PyObject *w, PyObject *z)
{
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]
- */
+
+ 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,16 +540,6 @@ float_pow(PyObject *v, PyObject *w, PyObject *z)
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);
}
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 108e658..eaf869f 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -575,6 +575,11 @@ int_pow(PyIntObject *v, PyIntObject *w, PyIntObject *z)
CONVERT_TO_LONG(v, iv);
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
arguments to double. */
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 4209419..4d4a959 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -1598,12 +1598,17 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
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);
+ 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);
}
z = (PyLongObject *)PyLong_FromLong(1L);