[Python-checkins] CVS: python/dist/src/Include pyport.h,2.33,2.34

Tim Peters tim_one@users.sourceforge.net
Tue, 04 Sep 2001 22:38:12 -0700


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

Modified Files:
	pyport.h 
Log Message:
Try to recover from that glibc's ldexp apparently doesn't set errno on
overflow.  Needs testing on Linux (test_long.py and test_long_future.py
especially).


Index: pyport.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/pyport.h,v
retrieving revision 2.33
retrieving revision 2.34
diff -C2 -d -r2.33 -r2.34
*** pyport.h	2001/08/29 21:37:09	2.33
--- pyport.h	2001/09/05 05:38:10	2.34
***************
*** 231,234 ****
--- 231,254 ----
  #define Py_IS_INFINITY(X) ((X) && (X)*0.5 == (X))
  
+ /* Py_OVERFLOWED(X)
+  * Return 1 iff a libm function overflowed.  Set errno to 0 before calling
+  * a libm function, and invoke this macro after, passing the function
+  * result.
+  * Caution:
+  *    This isn't reliable.  C99 no longer requires libm to set errno under
+  *        any exceptional condition, but does require +- HUGE_VAL return
+  *        values on overflow.  A 754 box *probably* maps HUGE_VAL to a
+  *        double infinity, and we're cool if that's so, unless the input
+  *        was an infinity and an infinity is the expected result.  A C89
+  *        system sets errno to ERANGE, so we check for that too.  We're
+  *	  out of luck if a C99 754 box doesn't map HUGE_VAL to +Inf, or
+  *	  if the returned result is a NaN, or if a C89 box returns HUGE_VAL
+  *	  in non-overflow cases.
+  *    X is evaluated more than once.
+  */
+ #define Py_OVERFLOWED(X) ((X) != 0.0 && (errno == ERANGE || \
+ 					 (X) == HUGE_VAL || \
+ 					 (X) == -HUGE_VAL))
+ 
  /**************************************************************************
  Prototypes that are missing from the standard include files on some systems