summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-03-22 02:48:46 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-03-22 02:48:46 (GMT)
commitbab22beda8583471caf44b2e91f0fc18b62d3405 (patch)
tree23e4ed332a0f28cfaaacc51b3cd95bfe052984d4 /Objects
parent366a1df7f1a940a77d2d3b8ac6425fe7353f43c6 (diff)
downloadcpython-bab22beda8583471caf44b2e91f0fc18b62d3405.zip
cpython-bab22beda8583471caf44b2e91f0fc18b62d3405.tar.gz
cpython-bab22beda8583471caf44b2e91f0fc18b62d3405.tar.bz2
SF bug 533198: Complex power underflow raises exception.
Konrad was too kind. Not only did it raise an exception, the specific exception it raised made no sense. These are old bugs in complex_pow() and friends: 1. Raising 0 to a negative power isn't a range error, it's a domain error, so changed c_pow() to set errno to EDOM in that case instead of ERANGE. 2. Changed complex_pow() to: A. Used the Py_ADJUST_ERANGE2 macro to try to clear errno of a spurious ERANGE error due to underflow in the libm pow() called by c_pow(). B. Produced different exceptions depending on the errno value: i) For errno==EDOM, raise ZeroDivisionError instead of ValueError. This is for consistency with the non-complex cases 0.0**-2 and 0**-2 and 0L**-2. ii) For errno==ERANGE, raise OverflowError. Bugfix candidate.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/complexobject.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 0bc388b..48a9afa 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -131,7 +131,7 @@ c_pow(Py_complex a, Py_complex b)
}
else if (a.real == 0. && a.imag == 0.) {
if (b.imag != 0. || b.real < 0.)
- errno = ERANGE;
+ errno = EDOM;
r.real = 0.;
r.imag = 0.;
}
@@ -456,11 +456,17 @@ complex_pow(PyComplexObject *v, PyObject *w, PyComplexObject *z)
p = c_pow(v->cval,exponent);
PyFPE_END_PROTECT(p)
- if (errno == ERANGE) {
- PyErr_SetString(PyExc_ValueError,
+ Py_ADJUST_ERANGE2(p.real, p.imag);
+ if (errno == EDOM) {
+ PyErr_SetString(PyExc_ZeroDivisionError,
"0.0 to a negative or complex power");
return NULL;
}
+ else if (errno == ERANGE) {
+ PyErr_SetString(PyExc_OverflowError,
+ "complex exponentiaion");
+ return NULL;
+ }
return PyComplex_FromCComplex(p);
}