2 dnl Copyright (C) 2010-2021 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, ilogbl(0.0L) is wrong.
75 dnl On AIX 7.1 in 64-bit mode, ilogbl(2^(LDBL_MIN_EXP-1)) is wrong.
76 dnl On Haiku 2017, it returns i-2 instead of i-1 for values between
77 dnl ca. 2^-16444 and ca. 2^-16382.
78 AC_DEFUN([gl_FUNC_ILOGBL_WORKS],
80 AC_REQUIRE([AC_PROG_CC])
81 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
82 AC_CACHE_CHECK([whether ilogbl works], [gl_cv_func_ilogbl_works],
88 /* Override the values of <float.h>, like done in float.in.h. */
89 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
91 # define LDBL_MIN_EXP (-16381)
93 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
95 # define LDBL_MIN_EXP (-16381)
97 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
99 # define LDBL_MIN_EXP DBL_MIN_EXP
101 #if defined __sgi && (LDBL_MANT_DIG >= 106)
102 # if defined __GNUC__
104 # define LDBL_MIN_EXP DBL_MIN_EXP
107 volatile long double x;
108 static int dummy (long double x) { return 0; }
109 int main (int argc, char *argv[])
111 int (* volatile my_ilogbl) (long double) = argc ? ilogbl : dummy;
113 /* This test fails on Cygwin 2.9. */
116 if (my_ilogbl (x) != FP_ILOGB0)
119 /* This test fails on AIX 7.1 in 64-bit mode. */
123 for (i = LDBL_MIN_EXP - 1; i < 0; i++)
125 if (x > 0.0L && my_ilogbl (x) != LDBL_MIN_EXP - 2)
128 /* This test fails on Haiku 2017. */
131 for (i = 1, x = (long double)1.0; i >= LDBL_MIN_EXP-100 && x > (long double)0.0; i--, x *= (long double)0.5)
132 if (my_ilogbl (x) != i - 1)
141 [gl_cv_func_ilogbl_works=yes],
142 [gl_cv_func_ilogbl_works=no],
145 gl_cv_func_ilogbl_works="guessing no" ;;
146 # Guess yes on native Windows.
147 mingw*) gl_cv_func_ilogbl_works="guessing yes" ;;
148 *) gl_cv_func_ilogbl_works="guessing yes" ;;