Add script for determining the set of symbols to export from a library.
[gnulib.git] / m4 / ilogb.m4
blob53c3f05f27e0d4da0c3e5b4ee2abf35cd84ce463
1 # ilogb.m4 serial 4
2 dnl Copyright (C) 2010-2019 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_ILOGB],
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   dnl Determine ILOGB_LIBM.
12   gl_MATHFUNC([ilogb], [int], [(double)])
13   if test $gl_cv_func_ilogb_no_libm = yes \
14      || test $gl_cv_func_ilogb_in_libm = yes; then
15     save_LIBS="$LIBS"
16     LIBS="$LIBS $ILOGB_LIBM"
17     gl_FUNC_ILOGB_WORKS
18     LIBS="$save_LIBS"
19     case "$gl_cv_func_ilogb_works" in
20       *yes) ;;
21       *) REPLACE_ILOGB=1 ;;
22     esac
23   else
24     HAVE_ILOGB=0
25   fi
26   if test $HAVE_ILOGB = 0 || test $REPLACE_ILOGB = 1; then
27     dnl Find libraries needed to link lib/ilogb.c.
28     AC_REQUIRE([gl_FUNC_FREXP])
29     AC_REQUIRE([gl_FUNC_ISNAND])
30     ILOGB_LIBM=
31     dnl Append $FREXP_LIBM to ILOGB_LIBM, avoiding gratuitous duplicates.
32     case " $ILOGB_LIBM " in
33       *" $FREXP_LIBM "*) ;;
34       *) ILOGB_LIBM="$ILOGB_LIBM $FREXP_LIBM" ;;
35     esac
36     dnl Append $ISNAND_LIBM to ILOGB_LIBM, avoiding gratuitous duplicates.
37     case " $ILOGB_LIBM " in
38       *" $ISNAND_LIBM "*) ;;
39       *) ILOGB_LIBM="$ILOGB_LIBM $ISNAND_LIBM" ;;
40     esac
41   fi
42   AC_SUBST([ILOGB_LIBM])
45 dnl Test whether ilogb() works.
46 dnl On OpenBSD 4.9, AIX 5.1, ilogb(0.0) is wrong.
47 dnl On NetBSD 5.1, OpenBSD 4.9, ilogb(Infinity) is wrong.
48 dnl On OpenBSD 4.9, ilogb(NaN) is wrong.
49 AC_DEFUN([gl_FUNC_ILOGB_WORKS],
51   AC_REQUIRE([AC_PROG_CC])
52   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
53   AC_CACHE_CHECK([whether ilogb works], [gl_cv_func_ilogb_works],
54     [
55       AC_RUN_IFELSE(
56         [AC_LANG_SOURCE([[
57 #include <limits.h>
58 #include <math.h>
59 /* Provide FP_ILOGB0, FP_ILOGBNAN, like in math.in.h.  */
60 #if defined FP_ILOGB0 && defined FP_ILOGBNAN
61 # if defined __HAIKU__
62   /* Haiku: match what ilogb() does */
63 #  undef FP_ILOGB0
64 #  undef FP_ILOGBNAN
65 #  define FP_ILOGB0   (- 2147483647 - 1) /* INT_MIN */
66 #  define FP_ILOGBNAN (- 2147483647 - 1) /* INT_MIN */
67 # endif
68 #else
69 # if defined __NetBSD__ || defined __sgi
70   /* NetBSD, IRIX 6.5: match what ilogb() does */
71 #  define FP_ILOGB0   INT_MIN
72 #  define FP_ILOGBNAN INT_MIN
73 # elif defined _AIX
74   /* AIX 5.1: match what ilogb() does in AIX >= 5.2 */
75 #  define FP_ILOGB0   INT_MIN
76 #  define FP_ILOGBNAN INT_MAX
77 # elif defined __sun
78   /* Solaris 9: match what ilogb() does */
79 #  define FP_ILOGB0   (- INT_MAX)
80 #  define FP_ILOGBNAN INT_MAX
81 # endif
82 #endif
83 volatile double x;
84 static double zero;
85 static int dummy (double x) { return 0; }
86 int main (int argc, char *argv[])
88   int (* volatile my_ilogb) (double) = argc ? ilogb : dummy;
89   int result = 0;
90   /* This test fails on OpenBSD 4.9, AIX 5.1.  */
91   {
92     x = 0.0;
93     if (my_ilogb (x) != FP_ILOGB0)
94       result |= 1;
95   }
96   /* This test fails on NetBSD 5.1, OpenBSD 4.9.  */
97   {
98     x = 1.0 / zero;
99     if (my_ilogb (x) != INT_MAX)
100       result |= 2;
101   }
102   /* This test fails on OpenBSD 4.9.  */
103   {
104     x = zero / zero;
105     if (my_ilogb (x) != FP_ILOGBNAN)
106       result |= 4;
107   }
108   return result;
110 ]])],
111         [gl_cv_func_ilogb_works=yes],
112         [gl_cv_func_ilogb_works=no],
113         [case "$host_os" in
114            aix* | openbsd* | netbsd* | solaris*)
115                    gl_cv_func_ilogb_works="guessing no" ;;
116                    # Guess yes on native Windows.
117            mingw*) gl_cv_func_ilogb_works="guessing yes" ;;
118            *)      gl_cv_func_ilogb_works="guessing yes" ;;
119          esac
120         ])
121     ])