>From 625f7aea332a6b43fd9be4ce91d805182a5feb0c Mon Sep 17 00:00:00 2001 From: Bruno Haible
Date: Sun, 29 Oct 2017 12:57:35 +0100 Subject: [PATCH 3/7] ilogbl: Ensure replacement on Haiku. * m4/ilogbl.m4 (gl_FUNC_ILOGBL): Invoke gl_FUNC_ILOGBL_WORKS and set REPLACE_ILOGBL if ilogbl does not work. (gl_FUNC_ILOGBL_WORKS): New macro. * lib/math.in.h (ilogbl): Replace if REPLACE_ILOGBL is 1. * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_ILOGBL. * modules/math (Makefile.am): Substitute REPLACE_ILOGBL. * modules/ilogbl (Depends-on, configure.ac): Consider REPLACE_ILOGBL. * doc/posix-functions/ilogbl.texi: Mention the Haiku problem. --- ChangeLog | 12 +++++++ doc/posix-functions/ilogbl.texi | 3 ++ lib/math.in.h | 13 +++++-- m4/ilogbl.m4 | 75 ++++++++++++++++++++++++++++++++++++++++- m4/math_h.m4 | 3 +- modules/ilogbl | 10 +++--- modules/math | 1 + 7 files changed, 108 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 53745fc..9bfd408 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2017-10-29 Bruno Haible + ilogbl: Ensure replacement on Haiku. + * m4/ilogbl.m4 (gl_FUNC_ILOGBL): Invoke gl_FUNC_ILOGBL_WORKS and set + REPLACE_ILOGBL if ilogbl does not work. + (gl_FUNC_ILOGBL_WORKS): New macro. + * lib/math.in.h (ilogbl): Replace if REPLACE_ILOGBL is 1. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_ILOGBL. + * modules/math (Makefile.am): Substitute REPLACE_ILOGBL. + * modules/ilogbl (Depends-on, configure.ac): Consider REPLACE_ILOGBL. + * doc/posix-functions/ilogbl.texi: Mention the Haiku problem. + +2017-10-29 Bruno Haible + expl: Ensure replacement on Haiku. * m4/expl.m4 (gl_FUNC_EXPL): Test whether an expl() return value is zero. diff --git a/doc/posix-functions/ilogbl.texi b/doc/posix-functions/ilogbl.texi index 9580a5c..f1ca24b 100644 --- a/doc/posix-functions/ilogbl.texi +++ b/doc/posix-functions/ilogbl.texi @@ -11,6 +11,9 @@ Portability problems fixed by Gnulib: @item This function is missing on some platforms: FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS. address@hidden +This function returns a wrong result for denormalized arguments on some platforms: +Haiku 2017. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/math.in.h b/lib/math.in.h index 09f822a..5681597 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -1223,10 +1223,19 @@ _GL_WARN_ON_USE (ilogb, "ilogb is unportable - " #endif #if @GNULIB_ILOGBL@ -# if address@hidden@ +# if @REPLACE_ILOGBL@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef ilogbl +# define ilogbl rpl_ilogbl +# endif +_GL_FUNCDECL_RPL (ilogbl, int, (long double x)); +_GL_CXXALIAS_RPL (ilogbl, int, (long double x)); +# else +# if address@hidden@ _GL_FUNCDECL_SYS (ilogbl, int, (long double x)); -# endif +# endif _GL_CXXALIAS_SYS (ilogbl, int, (long double x)); +# endif _GL_CXXALIASWARN (ilogbl); #elif defined GNULIB_POSIXCHECK # undef ilogbl diff --git a/m4/ilogbl.m4 b/m4/ilogbl.m4 index 44556a9..60cb141 100644 --- a/m4/ilogbl.m4 +++ b/m4/ilogbl.m4 @@ -1,4 +1,4 @@ -# ilogbl.m4 serial 1 +# ilogbl.m4 serial 2 dnl Copyright (C) 2010-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, @@ -36,8 +36,18 @@ AC_DEFUN([gl_FUNC_ILOGBL], LIBS="$save_LIBS" if test $gl_cv_func_ilogbl = yes; then ILOGBL_LIBM="$ILOGB_LIBM" + save_LIBS="$LIBS" + LIBS="$LIBS $ILOGBL_LIBM" + gl_FUNC_ILOGBL_WORKS + LIBS="$save_LIBS" + case "$gl_cv_func_ilogbl_works" in + *yes) ;; + *) REPLACE_ILOGBL=1 ;; + esac else HAVE_ILOGBL=0 + fi + if test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; then dnl Find libraries needed to link lib/ilogbl.c. if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then ILOGBL_LIBM="$ILOGB_LIBM" @@ -59,3 +69,66 @@ AC_DEFUN([gl_FUNC_ILOGBL], fi AC_SUBST([ILOGBL_LIBM]) ]) + +dnl Test whether ilogbl() works. +dnl On Haiku 2017, it returns i-2 instead of i-1 for values between +dnl ca. 2^-16444 and ca. 2^-16382. +AC_DEFUN([gl_FUNC_ILOGBL_WORKS], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether ilogbl works], [gl_cv_func_ilogbl_works], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include