fma: Work around glibc 2.43 regression

Bruno Haible via Gnulib discussion list <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Organization GNU
Message-ID <2554237.jE0xQCEvom@nimes>
Running a Gnulib testdir on Ubuntu Cinnamon 26.04, there is 1 test failure:

FAIL: test-fma2
===============

../../gltests/test-fma2.h:228: assertion 'result == expected' failed

FAIL test-fma2 (exit status: 134)

This patch provides a workaround.


2026-05-27  Bruno Haible  <[email protected]>

	fma: Work around glibc 2.43 regression.
	* m4/fma.m4 (gl_FUNC_FMA_WORKS): Check against glibc 2.43 bug.
	* doc/posix-functions/fma.texi: Mention glibc 2.43 as being buggy.

diff --git a/doc/posix-functions/fma.texi b/doc/posix-functions/fma.texi
index ec45e5286d..9be058efea 100644
--- a/doc/posix-functions/fma.texi
+++ b/doc/posix-functions/fma.texi
@@ -15,7 +15,9 @@
 FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, Solaris 9, MSVC 9.
 @item
 This function produces wrong results on some platforms:
-glibc 2.11, Mac OS X 10.5, FreeBSD 6.4/x86, NetBSD 8.0, OpenBSD 7.4/arm64, Cygwin 1.5, mingw.
+@c https://sourceware.org/bugzilla/show_bug.cgi?id=34183
+glibc 2.43,
+Mac OS X 10.5, FreeBSD 6.4/x86, NetBSD 8.0, OpenBSD 7.4/arm64, Cygwin 1.5, mingw.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/m4/fma.m4 b/m4/fma.m4
index 49c705df6c..cf9d7b888a 100644
--- a/m4/fma.m4
+++ b/m4/fma.m4
@@ -1,5 +1,5 @@
 # fma.m4
-# serial 9
+# serial 10
 dnl Copyright (C) 2011-2026 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -52,7 +52,8 @@ AC_DEFUN([gl_FUNC_FMA]
   AC_SUBST([FMA_LIBM])
 ])
 
-dnl Test whether fma() has any of the 7 known bugs of glibc 2.11.3 on x86_64.
+dnl Test whether fma() has any of the 7 known bugs of glibc 2.11.3 on x86_64
+dnl and the 1 known bug of glibc 2.43 on x86_64.
 AC_DEFUN([gl_FUNC_FMA_WORKS],
 [
   AC_REQUIRE([AC_PROG_CC])
@@ -134,6 +135,21 @@ AC_DEFUN([gl_FUNC_FMA_WORKS]
        therefore the rounding must round down and produce (2^53 - 2^0).  */
     volatile double expected = ldexp (1.0, DBL_MANT_DIG) - 1.0;
     volatile double result = my_fma (x, y, z);
+    if (result != expected)
+      failed_tests |= 8;
+  }
+  /* This test fails on glibc 2.43 on x86_64.
+     <https://sourceware.org/bugzilla/show_bug.cgi?id=34183>  */
+  {
+    volatile double x = 1.0 + 1.0 / (double) (1U << 21); /* 2^0 + 2^-21 */
+    volatile double y = x; /* 2^0 + 2^-21 */
+    volatile double z = (double) (1U << 11); /* 2^11 */
+    /* x * y + z with infinite precision: 2^11 + 2^0 + 2^-20 + 2^-42.
+       Lies between (2^11 + 2^0 + 2^-20) and (2^11 + 2^0 + 2^-20 + 2^-41).
+       By the round-to-even rule, the rounding must round down and produce
+       (2^11 + 2^0 + 2^-20).  */
+    volatile double expected = 2049.00000095367431640625;
+    volatile double result = my_fma (x, y, z);
     if (result != expected)
       failed_tests |= 16;
   }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.