2 dnl Copyright (C) 2010-2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_ILOGBL],
9 AC_REQUIRE([gl_MATH_H_DEFAULTS])
10 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
11 AC_REQUIRE([gl_FUNC_ILOGB])
13 dnl Persuade glibc <math.h> to declare ilogbl().
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16 dnl Test whether ilogbl() exists. Assume that ilogbl(), if it exists, is
17 dnl defined in the same library as ilogb().
19 LIBS="$LIBS $ILOGB_LIBM"
20 AC_CACHE_CHECK([for ilogbl],
25 [[#ifndef __NO_MATH_INLINES
26 # define __NO_MATH_INLINES 1 /* for glibc */
29 int (*funcptr) (long double) = ilogbl;
31 [[return (funcptr (x) % 2) == 0
32 || (ilogbl (x) % 2) == 0;]])],
33 [gl_cv_func_ilogbl=yes],
34 [gl_cv_func_ilogbl=no])
37 if test $gl_cv_func_ilogbl = yes; then
38 ILOGBL_LIBM="$ILOGB_LIBM"
40 LIBS="$LIBS $ILOGBL_LIBM"
43 case "$gl_cv_func_ilogbl_works" in
45 *) REPLACE_ILOGBL=1 ;;
50 if test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; then
51 dnl Find libraries needed to link lib/ilogbl.c.
52 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
53 ILOGBL_LIBM="$ILOGB_LIBM"
55 AC_REQUIRE([gl_FUNC_FREXPL])
56 AC_REQUIRE([gl_FUNC_ISNANL])
58 dnl Append $FREXPL_LIBM to ILOGBL_LIBM, avoiding gratuitous duplicates.
59 case " $ILOGBL_LIBM " in
60 *" $FREXPL_LIBM "*) ;;
61 *) ILOGBL_LIBM="$ILOGBL_LIBM $FREXPL_LIBM" ;;
63 dnl Append $ISNANL_LIBM to ILOGBL_LIBM, avoiding gratuitous duplicates.
64 case " $ILOGBL_LIBM " in
65 *" $ISNANL_LIBM "*) ;;
66 *) ILOGBL_LIBM="$ILOGBL_LIBM $ISNANL_LIBM" ;;
70 AC_SUBST([ILOGBL_LIBM])
73 dnl Test whether ilogbl() works.
74 dnl On Cygwin 2.9, ilogb(0.0L) is wrong.
75 dnl On Haiku 2017, it returns i-2 instead of i-1 for values between
76 dnl ca. 2^-16444 and ca. 2^-16382.
77 AC_DEFUN([gl_FUNC_ILOGBL_WORKS],
79 AC_REQUIRE([AC_PROG_CC])
80 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
81 AC_CACHE_CHECK([whether ilogbl works], [gl_cv_func_ilogbl_works],
87 /* Override the values of <float.h>, like done in float.in.h. */
88 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
90 # define LDBL_MIN_EXP (-16381)
92 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
94 # define LDBL_MIN_EXP (-16381)
96 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
98 # define LDBL_MIN_EXP DBL_MIN_EXP
100 #if defined __sgi && (LDBL_MANT_DIG >= 106)
101 # if defined __GNUC__
103 # define LDBL_MIN_EXP DBL_MIN_EXP
106 volatile long double x;
107 static int dummy (long double x) { return 0; }
108 int main (int argc, char *argv[])
110 int (* volatile my_ilogbl) (long double) = argc ? ilogbl : dummy;
112 /* This test fails on Cygwin 2.9. */
115 if (my_ilogbl (x) != FP_ILOGB0)
118 /* This test fails on Haiku 2017. */
121 for (i = 1, x = (long double)1.0; i >= LDBL_MIN_EXP-100 && x > (long double)0.0; i--, x *= (long double)0.5)
122 if (my_ilogbl (x) != i - 1)
131 [gl_cv_func_ilogbl_works=yes],
132 [gl_cv_func_ilogbl_works=no],
134 haiku*) gl_cv_func_ilogbl_works="guessing no" ;;
135 # Guess yes on native Windows.
136 mingw*) gl_cv_func_ilogbl_works="guessing yes" ;;
137 *) gl_cv_func_ilogbl_works="guessing yes" ;;