Discussion:
workaround glibc bug in logbl()
(too old to reply)
Bruno Haible
2017-07-01 15:13:13 UTC
Permalink
Raw Message
On Linux/PowerPC64LE, with glibc-2.23 (under qemu), I'm seeing this
gnulib test failure:

FAIL: test-logbl
================

../../gltests/test-logb.h:94: assertion 'y == (DOUBLE)(i - 1)' failed
qemu: uncaught target signal 6 (Aborted) - core dumped

When I add an fprintf statement there:
fprintf (stderr, "%d %Lg %Lg\n", i, x, y); fflush(stderr);

the output is:
...
-1016 -7.12024e-307 -1017
-1017 -3.56012e-307 -1018
-1018 -1.78006e-307 -1019
-1019 -8.9003e-308 -1020
-1020 -4.45015e-308 -1021
-1021 -2.22507e-308 -1022
-1022 -1.11254e-308 -1011 <== HERE the result should be -1023.

Since the earlier-reported glibc bugs [1][2] are fixed in glibc 2.23,
it is a newer glibc bug [3].

This patch provides a workaround in gnulib.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=13956
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=18030
[3] https://sourceware.org/bugzilla/show_bug.cgi?id=21280


2017-07-01 Bruno Haible <***@clisp.org>

logbl: Work around a glibc bug on PowerPC64LE.
* m4/logbl.m4 (gl_FUNC_LOGBL_WORKS): Test also negative subnormal
numbers.
* doc/posix-functions/logbl.texi: Update.

diff --git a/doc/posix-functions/logbl.texi b/doc/posix-functions/logbl.texi
index fd9c384..857c776 100644
--- a/doc/posix-functions/logbl.texi
+++ b/doc/posix-functions/logbl.texi
@@ -13,7 +13,8 @@ This function is missing on some platforms:
FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, older IRIX 6.5, Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS.
@item
This function produces wrong results for subnormal numbers on some platforms:
-glibc 2.11/ppc, glibc 2.7/sparc, glibc 2.7/hppa, Solaris 11 2011-11.
+glibc 2.11/powerpc, glibc 2.7/sparc, glibc 2.7/hppa, Solaris 11 2011-11,
+glibc 2.23/powerpc64le.
@end itemize

Portability problems not fixed by Gnulib:
diff --git a/m4/logbl.m4 b/m4/logbl.m4
index db0a36d..5e236f5 100644
--- a/m4/logbl.m4
+++ b/m4/logbl.m4
@@ -1,4 +1,4 @@
-# logbl.m4 serial 2
+# logbl.m4 serial 3
dnl Copyright (C) 2012-2017 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -54,8 +54,10 @@ AC_DEFUN([gl_FUNC_LOGBL],
])

dnl Test whether logbl() works.
-dnl On glibc 2.11/ppc, glibc 2.7/sparc, glibc 2.7/hppa, Solaris 10/SPARC, the
-dnl return value for subnormal (denormalized) arguments is too large.
+dnl On glibc 2.11/powerpc, glibc 2.7/sparc, glibc 2.7/hppa, Solaris 10/SPARC,
+dnl the return value for subnormal (denormalized) arguments is too large.
+dnl On glibc 2.23/powerpc64le, the return value for negative subnormal arguments
+dnl is too large.
AC_DEFUN([gl_FUNC_LOGBL_WORKS],
[
AC_REQUIRE([AC_PROG_CC])
@@ -94,6 +96,11 @@ int main ()
if ((i == LDBL_MIN_EXP - 1 || i == LDBL_MIN_EXP - 54)
&& (x > 0.0L && !(logbl (x) == (long double)(i - 1))))
return 1;
+ for (i = 1, x = -1.0L; i >= LDBL_MIN_EXP - 54; i--, x *= 0.5L)
+ /* Either x = -2^(i-1) or x = 0.0. */
+ if ((i == LDBL_MIN_EXP - 1 || i == LDBL_MIN_EXP - 54)
+ && (x < 0.0L && !(logbl (x) == (long double)(i - 1))))
+ return 1;
return 0;
}
]])],

Loading...