[Python-checkins] CVS: python/dist/src/Objects complexobject.c,2.53.4.1,2.53.4.2
Michael Hudson
mwh@users.sourceforge.net
Mon, 25 Mar 2002 05:21:43 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv4722
Modified Files:
Tag: release22-maint
complexobject.c
Log Message:
backport tim_one's checkin of
revision 2.55 of complexobject.c
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.
Index: complexobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/complexobject.c,v
retrieving revision 2.53.4.1
retrieving revision 2.53.4.2
diff -C2 -d -r2.53.4.1 -r2.53.4.2
*** complexobject.c 22 Feb 2002 13:23:33 -0000 2.53.4.1
--- complexobject.c 25 Mar 2002 13:21:41 -0000 2.53.4.2
***************
*** 132,136 ****
else if (a.real == 0. && a.imag == 0.) {
if (b.imag != 0. || b.real < 0.)
! errno = ERANGE;
r.real = 0.;
r.imag = 0.;
--- 132,136 ----
else if (a.real == 0. && a.imag == 0.) {
if (b.imag != 0. || b.real < 0.)
! errno = EDOM;
r.real = 0.;
r.imag = 0.;
***************
*** 457,463 ****
PyFPE_END_PROTECT(p)
! if (errno == ERANGE) {
! PyErr_SetString(PyExc_ValueError,
"0.0 to a negative or complex power");
return NULL;
}
--- 457,469 ----
PyFPE_END_PROTECT(p)
! 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;
}