maint: update copyright
[gnulib.git] / m4 / ilogb.m4
1 # ilogb.m4 serial 1
2 dnl Copyright (C) 2010-2014 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.
6
7 AC_DEFUN([gl_FUNC_ILOGB],
8 [
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10
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])
43 ])
44
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],
50 [
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 __NetBSD__ || defined __sgi
62   /* NetBSD, IRIX 6.5: match what ilogb() does */
63 #  define FP_ILOGB0   INT_MIN
64 #  define FP_ILOGBNAN INT_MIN
65 # elif defined _AIX
66   /* AIX 5.1: match what ilogb() does in AIX >= 5.2 */
67 #  define FP_ILOGB0   INT_MIN
68 #  define FP_ILOGBNAN INT_MAX
69 # elif defined __sun
70   /* Solaris 9: match what ilogb() does */
71 #  define FP_ILOGB0   (- INT_MAX)
72 #  define FP_ILOGBNAN INT_MAX
73 # endif
74 #endif
75 volatile double x;
76 static double zero;
77 static int dummy (double x) { return 0; }
78 int main (int argc, char *argv[])
79 {
80   int (*my_ilogb) (double) = argc ? ilogb : dummy;
81   int result = 0;
82   /* This test fails on OpenBSD 4.9, AIX 5.1.  */
83   {
84     x = 0.0;
85     if (my_ilogb (x) != FP_ILOGB0)
86       result |= 1;
87   }
88   /* This test fails on NetBSD 5.1, OpenBSD 4.9.  */
89   {
90     x = 1.0 / zero;
91     if (my_ilogb (x) != INT_MAX)
92       result |= 2;
93   }
94   /* This test fails on OpenBSD 4.9.  */
95   {
96     x = zero / zero;
97     if (my_ilogb (x) != FP_ILOGBNAN)
98       result |= 4;
99   }
100   return result;
101 }
102 ]])],
103         [gl_cv_func_ilogb_works=yes],
104         [gl_cv_func_ilogb_works=no],
105         [case "$host_os" in
106            aix* | openbsd* | netbsd* | solaris*)
107               gl_cv_func_ilogb_works="guessing no";;
108            *) gl_cv_func_ilogb_works="guessing yes";;
109          esac
110         ])
111     ])
112 ])