[Python-checkins] CVS: python/dist/src/Modules cmathmodule.c,2.27,2.28

Tim Peters tim_one@users.sourceforge.net
Fri, 08 Mar 2002 20:58:26 -0800


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

Modified Files:
	cmathmodule.c 
Log Message:
SF bug 525705:  [2.2] underflow raise OverflowException.
Another year in the quest to out-guess random C behavior.

Added macros Py_ADJUST_ERANGE1(X) and Py_ADJUST_ERANGE2(X, Y).  The latter
is useful for functions with complex results.  Two corrections to errno-
after-libm-call are attempted:

1. If the platform set errno to ERANGE due to underflow, clear errno.
   Some unknown subset of libm versions and link options do this.  It's
   allowed by C89, but I never figured anyone would do it.

2. If the platform did not set errno but overflow occurred, force
   errno to ERANGE.  C89 required setting errno to ERANGE, but C99
   doesn't.  Some unknown subset of libm versions and link options do
   it the C99 way now.

Bugfix candidate, but hold off until some Linux people actually try it,
with and without -lieee.  I'll send a help plea to Python-Dev.


Index: cmathmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cmathmodule.c,v
retrieving revision 2.27
retrieving revision 2.28
diff -C2 -d -r2.27 -r2.28
*** cmathmodule.c	6 Sep 2001 08:16:17 -0000	2.27
--- cmathmodule.c	9 Mar 2002 04:58:24 -0000	2.28
***************
*** 338,343 ****
  	x = (*func)(x);
  	PyFPE_END_PROTECT(x)
! 	Py_SET_ERANGE_IF_OVERFLOW(x.real);
! 	Py_SET_ERANGE_IF_OVERFLOW(x.imag);
  	if (errno != 0)
  		return math_error();
--- 338,342 ----
  	x = (*func)(x);
  	PyFPE_END_PROTECT(x)
! 	Py_ADJUST_ERANGE2(x.real, x.imag);
  	if (errno != 0)
  		return math_error();