>From a84cef90957f2379cc0df6bd908317fc441971ce Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 12 Aug 2018 15:28:20 -0700 Subject: [PATCH] Port better to x86 -fexcess-precision=fast Problem reported by Eli Zaretskii in: https://lists.gnu.org/r/emacs-devel/2018-08/msg00380.html * src/data.c (arithcompare): Work around incompatibility between gcc -fexcess-precision=fast and the C standard on x86, by capturing the results of floating-point comparisons before the excess precision spontaneously decays. Although this fix might not work in general, it does work here and is probably good enough for the platforms we care about. --- src/data.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/data.c b/src/data.c index c8a9c6b378..7b8dd45c94 100644 --- a/src/data.c +++ b/src/data.c @@ -2492,7 +2492,7 @@ arithcompare (Lisp_Object num1, Lisp_Object num2, { double f1, f2; EMACS_INT i1, i2; - bool fneq; + bool lt, eq, gt; bool test; CHECK_NUMBER_COERCE_MARKER (num1); @@ -2502,10 +2502,13 @@ arithcompare (Lisp_Object num1, Lisp_Object num2, return bignumcompare (num1, num2, comparison); /* If either arg is floating point, set F1 and F2 to the 'double' - approximations of the two arguments, and set FNEQ if floating-point - comparison reports that F1 is not equal to F2, possibly because F1 - or F2 is a NaN. Regardless, set I1 and I2 to integers that break - ties if the floating-point comparison is either not done or reports + approximations of the two arguments, and set LT, EQ, and GT to + the <, ==, > floating-point comparisons of F1 and F2 + respectively, taking care to avoid problems if either is a NaN, + and trying to avoid problems on platforms where variables (in + violation of the C standard) can contain excess precision. + Regardless, set I1 and I2 to integers that break ties if the + floating-point comparison is either not done or reports equality. */ if (FLOATP (num1)) @@ -2528,7 +2531,9 @@ arithcompare (Lisp_Object num1, Lisp_Object num2, to I2 will break the tie correctly. */ i1 = f2 = i2 = XFIXNUM (num2); } - fneq = f1 != f2; + lt = f1 < f2; + eq = f1 == f2; + gt = f1 > f2; } else { @@ -2539,39 +2544,49 @@ arithcompare (Lisp_Object num1, Lisp_Object num2, converse of comparing float to integer (see above). */ i2 = f1 = i1; f2 = XFLOAT_DATA (num2); - fneq = f1 != f2; + lt = f1 < f2; + eq = f1 == f2; + gt = f1 > f2; } else { i2 = XFIXNUM (num2); - fneq = false; + eq = true; } } + if (eq) + { + /* Break a floating-point tie by comparing the integers. */ + lt = i1 < i2; + eq = i1 == i2; + gt = i1 > i2; + } + switch (comparison) { case ARITH_EQUAL: - test = !fneq && i1 == i2; + test = eq; break; case ARITH_NOTEQUAL: - test = fneq || i1 != i2; + test = !eq; break; case ARITH_LESS: - test = fneq ? f1 < f2 : i1 < i2; + test = lt; break; case ARITH_LESS_OR_EQUAL: - test = fneq ? f1 <= f2 : i1 <= i2; + test = lt | eq; break; case ARITH_GRTR: - test = fneq ? f1 > f2 : i1 > i2; + test = gt; break; case ARITH_GRTR_OR_EQUAL: - test = fneq ? f1 >= f2 : i1 >= i2; + test = gt | eq; break; default: -- 2.17.1