Merged revisions 68296,68299 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r68296 | mark.dickinson | 2009-01-04 12:29:36 +0000 (Sun, 04 Jan 2009) | 6 lines

  Add autoconf test to detect x87-style double rounding, as described in
  issue #2937.  This information can be helpful for diagnosing platform-
  specific problems in math and cmath.  The result of the test also
  serves as a fairly reliable indicator of whether the x87 floating-point
  instructions (as opposed to SSE2) are in use on Intel x86/x86_64 systems.
........
  r68299 | mark.dickinson | 2009-01-04 13:57:26 +0000 (Sun, 04 Jan 2009) | 4 lines

  isinf and isnan are macros, not functions; fix configure script
  to use AC_CHECK_DECLS instead of AC_CHECK_FUNCS for these.
  (See discussion in issue #4506)
........
diff --git a/configure.in b/configure.in
index 394c804..d80e7a7 100644
--- a/configure.in
+++ b/configure.in
@@ -3056,6 +3056,44 @@
 LIBS_SAVE=$LIBS
 LIBS="$LIBS $LIBM"
 
+# Detect whether system arithmetic is subject to x87-style double
+# rounding issues.  The result of this test has little meaning on non
+# IEEE 754 platforms.  On IEEE 754, test should return 1 if rounding
+# mode is round-to-nearest and double rounding issues are present, and
+# 0 otherwise.  See http://bugs.python.org/issue2937 for more info.
+AC_MSG_CHECKING(for x87-style double rounding)
+AC_CACHE_VAL(ac_cv_x87_double_rounding, [
+AC_TRY_RUN([
+#include <stdlib.h>
+#include <math.h>
+int main() {
+    volatile double x, y, z;
+    /* 1./(1-2**-53) -> 1+2**-52 (correct), 1.0 (double rounding) */
+    x = 0.99999999999999989; /* 1-2**-53 */
+    y = 1./x;
+    if (y != 1.)
+        exit(0);
+    /* 1e16+2.99999 -> 1e16+2. (correct), 1e16+4. (double rounding) */
+    x = 1e16;
+    y = 2.99999;
+    z = x + y;
+    if (z != 1e16+4.)
+        exit(0);
+    /* both tests show evidence of double rounding */
+    exit(1);
+}
+],
+ac_cv_x87_double_rounding=no,
+ac_cv_x87_double_rounding=yes,
+ac_cv_x87_double_rounding=no)])
+AC_MSG_RESULT($ac_cv_x87_double_rounding)
+if test "$ac_cv_x87_double_rounding" = yes
+then
+  AC_DEFINE(X87_DOUBLE_ROUNDING, 1,
+  [Define if arithmetic is subject to x87-style double rounding issue])
+fi
+
+
 # On FreeBSD 6.2, it appears that tanh(-0.) returns 0. instead of
 # -0. on some architectures.
 AC_MSG_CHECKING(whether tanh preserves the sign of zero)
@@ -3084,7 +3122,8 @@
 
 AC_REPLACE_FUNCS(hypot)
 
-AC_CHECK_FUNCS(acosh asinh atanh copysign expm1 finite isinf isnan log1p)
+AC_CHECK_FUNCS([acosh asinh atanh copysign expm1 finite log1p])
+AC_CHECK_DECLS([isinf, isnan, isfinite], [], [], [[#include <math.h>]])
 
 LIBS=$LIBS_SAVE