From 08afe3dc6c9d88ea9c55231948c87f11470cb1f8 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 6 Jan 2021 19:59:10 +0100 Subject: [PATCH] logb: Fix test failure on glibc/powerpc. * doc/posix-functions/logb.texi: Update platform info. * m4/logb.m4 (gl_FUNC_LOGB_WORKS): Test against bug with negative subnormal numbers. --- ChangeLog | 7 +++++++ doc/posix-functions/logb.texi | 2 +- m4/logb.m4 | 32 ++++++++++++++++++++++++-------- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index b68667bcf3..0831c85e1c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2021-01-06 Bruno Haible + + logb: Fix test failure on glibc/powerpc. + * doc/posix-functions/logb.texi: Update platform info. + * m4/logb.m4 (gl_FUNC_LOGB_WORKS): Test against bug with negative + subnormal numbers. + 2021-01-06 Paul Eggert libc-config: simplify clang __has_* macros diff --git a/doc/posix-functions/logb.texi b/doc/posix-functions/logb.texi index 799628da06..ea9b3f5f75 100644 --- a/doc/posix-functions/logb.texi +++ b/doc/posix-functions/logb.texi @@ -16,7 +16,7 @@ This function is missing a declaration on some platforms: Cygwin 1.5.x. @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.4, Cygwin 1.5.x. +glibc 2.17/ppc, glibc 2.7/sparc, glibc 2.7/hppa, Solaris 11.4, Cygwin 1.5.x. @end itemize Portability problems not fixed by Gnulib: diff --git a/m4/logb.m4 b/m4/logb.m4 index 68e2c854d6..cd803c1002 100644 --- a/m4/logb.m4 +++ b/m4/logb.m4 @@ -1,4 +1,4 @@ -# logb.m4 serial 8 +# logb.m4 serial 9 dnl Copyright (C) 2010-2021 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -87,6 +87,8 @@ dnl Test whether logb() works. dnl On glibc 2.11/ppc, glibc 2.7/sparc, glibc 2.7/hppa, Solaris 10/SPARC, dnl Solaris 11.4/x86_64, Cygwin 1.5.x, the return value for subnormal dnl (denormalized) arguments is too large. +dnl On glibc 2.17/ppc likewise but only for negative subnormal (denormalized) +dnl arguments. AC_DEFUN([gl_FUNC_LOGB_WORKS], [ AC_REQUIRE([AC_PROG_CC]) @@ -105,13 +107,27 @@ double logb (double); volatile double x; int main () { - int i; - for (i = 1, x = 1.0; i >= DBL_MIN_EXP; i--, x *= 0.5) - ; - /* Here i = DBL_MIN_EXP - 1. Either x = 2^(i-1) is subnormal or x = 0.0. */ - if (x > 0.0 && !(logb (x) == (double)(i - 1))) - return 1; - return 0; + int result = 0; + /* This test fails on 2.11/ppc, glibc 2.7/sparc, glibc 2.7/hppa, + Solaris 10/SPARC, Solaris 11.4/x86_64, Cygwin 1.5.x. */ + { + int i; + for (i = 1, x = 1.0; i >= DBL_MIN_EXP; i--, x *= 0.5) + ; + /* Here i = DBL_MIN_EXP - 1. Either x = 2^(i-1) is subnormal or x = 0.0. */ + if (x > 0.0 && !(logb (x) == (double)(i - 1))) + result |= 1; + } + /* This test fails on glibc 2.17/ppc. */ + { + int i; + for (i = 1, x = -1.0; i >= DBL_MIN_EXP; i--, x *= 0.5) + ; + /* Here i = DBL_MIN_EXP - 1. Either x = -2^(i-1) is subnormal or x = -0.0. */ + if (x < 0.0 && !(logb (x) == (double)(i - 1))) + result |= 2; + } + return result; } ]])], [gl_cv_func_logb_works=yes], -- 2.11.4.GIT