glob.c: Silence warning about void pointer arithmetic
[gnulib.git] / m4 / ilogbl.m4
blob60cb14118e1cba3af5b8b0a2b3c6c40c50d0c95a
1 # ilogbl.m4 serial 2
2 dnl Copyright (C) 2010-2017 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().
18   save_LIBS="$LIBS"
19   LIBS="$LIBS $ILOGB_LIBM"
20   AC_CACHE_CHECK([for ilogbl],
21     [gl_cv_func_ilogbl],
22     [
23       AC_LINK_IFELSE(
24         [AC_LANG_PROGRAM(
25            [[#ifndef __NO_MATH_INLINES
26              # define __NO_MATH_INLINES 1 /* for glibc */
27              #endif
28              #include <math.h>
29              int (*funcptr) (long double) = ilogbl;
30              long double x;]],
31            [[return (funcptr (x) % 2) == 0
32                     || (ilogbl (x) % 2) == 0;]])],
33         [gl_cv_func_ilogbl=yes],
34         [gl_cv_func_ilogbl=no])
35     ])
36   LIBS="$save_LIBS"
37   if test $gl_cv_func_ilogbl = yes; then
38     ILOGBL_LIBM="$ILOGB_LIBM"
39     save_LIBS="$LIBS"
40     LIBS="$LIBS $ILOGBL_LIBM"
41     gl_FUNC_ILOGBL_WORKS
42     LIBS="$save_LIBS"
43     case "$gl_cv_func_ilogbl_works" in
44       *yes) ;;
45       *) REPLACE_ILOGBL=1 ;;
46     esac
47   else
48     HAVE_ILOGBL=0
49   fi
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"
54     else
55       AC_REQUIRE([gl_FUNC_FREXPL])
56       AC_REQUIRE([gl_FUNC_ISNANL])
57       ILOGBL_LIBM=
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" ;;
62       esac
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" ;;
67       esac
68     fi
69   fi
70   AC_SUBST([ILOGBL_LIBM])
73 dnl Test whether ilogbl() works.
74 dnl On Haiku 2017, it returns i-2 instead of i-1 for values between
75 dnl ca. 2^-16444 and ca. 2^-16382.
76 AC_DEFUN([gl_FUNC_ILOGBL_WORKS],
78   AC_REQUIRE([AC_PROG_CC])
79   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
80   AC_CACHE_CHECK([whether ilogbl works], [gl_cv_func_ilogbl_works],
81     [
82       AC_RUN_IFELSE(
83         [AC_LANG_SOURCE([[
84 #include <float.h>
85 #include <math.h>
86 /* Override the values of <float.h>, like done in float.in.h.  */
87 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
88 # undef LDBL_MIN_EXP
89 # define LDBL_MIN_EXP    (-16381)
90 #endif
91 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
92 # undef LDBL_MIN_EXP
93 # define LDBL_MIN_EXP    (-16381)
94 #endif
95 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
96 # undef LDBL_MIN_EXP
97 # define LDBL_MIN_EXP DBL_MIN_EXP
98 #endif
99 #if defined __sgi && (LDBL_MANT_DIG >= 106)
100 # if defined __GNUC__
101 #  undef LDBL_MIN_EXP
102 #  define LDBL_MIN_EXP DBL_MIN_EXP
103 # endif
104 #endif
105 volatile long double x;
106 static int dummy (long double x) { return 0; }
107 int main (int argc, char *argv[])
109   int (*my_ilogbl) (long double) = argc ? ilogbl : dummy;
110   int result = 0;
111   /* This test fails on Haiku 2017.  */
112   {
113     int i;
114     for (i = 1, x = (long double)1.0; i >= LDBL_MIN_EXP-100 && x > (long double)0.0; i--, x *= (long double)0.5)
115       if (my_ilogbl (x) != i - 1)
116         {
117           result |= 1;
118           break;
119         }
120   }
121   return result;
123 ]])],
124         [gl_cv_func_ilogbl_works=yes],
125         [gl_cv_func_ilogbl_works=no],
126         [case "$host_os" in
127            haiku*) gl_cv_func_ilogbl_works="guessing no" ;;
128                    # Guess yes on native Windows.
129            mingw*) gl_cv_func_ilogbl_works="guessing yes" ;;
130            *)      gl_cv_func_ilogbl_works="guessing yes" ;;
131          esac
132         ])
133     ])