>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 +#include +/* Override the values of , like done in float.in.h. */ +#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__) +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP (-16381) +#endif +#if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__) +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP (-16381) +#endif +#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__ +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP DBL_MIN_EXP +#endif +#if defined __sgi && (LDBL_MANT_DIG >= 106) +# if defined __GNUC__ +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP DBL_MIN_EXP +# endif +#endif +volatile long double x; +static int dummy (long double x) { return 0; } +int main (int argc, char *argv[]) +{ + int (*my_ilogbl) (long double) = argc ? ilogbl : dummy; + int result = 0; + /* This test fails on Haiku 2017. */ + { + int i; + for (i = 1, x = (long double)1.0; i >= LDBL_MIN_EXP-100 && x > (long double)0.0; i--, x *= (long double)0.5) + if (my_ilogbl (x) != i - 1) + { + result |= 1; + break; + } + } + return result; +} +]])], + [gl_cv_func_ilogbl_works=yes], + [gl_cv_func_ilogbl_works=no], + [case "$host_os" in + haiku*) gl_cv_func_ilogbl_works="guessing no" ;; + # Guess yes on native Windows. + mingw*) gl_cv_func_ilogbl_works="guessing yes" ;; + *) gl_cv_func_ilogbl_works="guessing yes" ;; + esac + ]) + ]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 6db72ca..b9a432e 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 115 +# math_h.m4 serial 116 dnl Copyright (C) 2007-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, @@ -291,6 +291,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], REPLACE_HYPOTL=0; AC_SUBST([REPLACE_HYPOTL]) REPLACE_ILOGB=0; AC_SUBST([REPLACE_ILOGB]) REPLACE_ILOGBF=0; AC_SUBST([REPLACE_ILOGBF]) + REPLACE_ILOGBL=0; AC_SUBST([REPLACE_ILOGBL]) REPLACE_ISFINITE=0; AC_SUBST([REPLACE_ISFINITE]) REPLACE_ISINF=0; AC_SUBST([REPLACE_ISINF]) REPLACE_ISNAN=0; AC_SUBST([REPLACE_ISNAN]) diff --git a/modules/ilogbl b/modules/ilogbl index d31ad26..3d321aa 100644 --- a/modules/ilogbl +++ b/modules/ilogbl @@ -10,14 +10,14 @@ m4/mathfunc.m4 Depends-on: math extensions -ilogb [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] -isfinite [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] -frexpl [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] -isnanl [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +ilogb [{ test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] +isfinite [{ test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +frexpl [{ test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +isnanl [{ test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] configure.ac: gl_FUNC_ILOGBL -if test $HAVE_ILOGBL = 0; then +if test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; then AC_LIBOBJ([ilogbl]) fi gl_MATH_MODULE_INDICATOR([ilogbl]) diff --git a/modules/math b/modules/math index 2f553ba..d539518 100644 --- a/modules/math +++ b/modules/math @@ -260,6 +260,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''REPLACE_HYPOTL''@|$(REPLACE_HYPOTL)|g' \ -e 's|@''REPLACE_ILOGB''@|$(REPLACE_ILOGB)|g' \ -e 's|@''REPLACE_ILOGBF''@|$(REPLACE_ILOGBF)|g' \ + -e 's|@''REPLACE_ILOGBL''@|$(REPLACE_ILOGBL)|g' \ -e 's|@''REPLACE_ISFINITE''@|$(REPLACE_ISFINITE)|g' \ -e 's|@''REPLACE_ISINF''@|$(REPLACE_ISINF)|g' \ -e 's|@''REPLACE_ISNAN''@|$(REPLACE_ISNAN)|g' \ -- 2.7.4