maint: update copyright
[gnulib.git] / m4 / ilogbf.m4
1 # ilogbf.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_ILOGBF],
8 [
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10
11   dnl Persuade glibc <math.h> to declare ilogbf().
12   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
13
14   dnl Determine ILOGBF_LIBM.
15   gl_MATHFUNC([ilogbf], [int], [(float)])
16   if test $gl_cv_func_ilogbf_no_libm = yes \
17      || test $gl_cv_func_ilogbf_in_libm = yes; then
18     save_LIBS="$LIBS"
19     LIBS="$LIBS $ILOGBF_LIBM"
20     gl_FUNC_ILOGBF_WORKS
21     LIBS="$save_LIBS"
22     case "$gl_cv_func_ilogbf_works" in
23       *yes) ;;
24       *) REPLACE_ILOGBF=1 ;;
25     esac
26   else
27     HAVE_ILOGBF=0
28   fi
29   if test $HAVE_ILOGBF = 0 || test $REPLACE_ILOGBF = 1; then
30     dnl Find libraries needed to link lib/ilogbf.c.
31     AC_REQUIRE([gl_FUNC_FREXPF])
32     AC_REQUIRE([gl_FUNC_ISNANF])
33     ILOGBF_LIBM=
34     dnl Append $FREXPF_LIBM to ILOGBF_LIBM, avoiding gratuitous duplicates.
35     case " $ILOGBF_LIBM " in
36       *" $FREXPF_LIBM "*) ;;
37       *) ILOGBF_LIBM="$ILOGBF_LIBM $FREXPF_LIBM" ;;
38     esac
39     dnl Append $ISNANF_LIBM to ILOGBF_LIBM, avoiding gratuitous duplicates.
40     case " $ILOGBF_LIBM " in
41       *" $ISNANF_LIBM "*) ;;
42       *) ILOGBF_LIBM="$ILOGBF_LIBM $ISNANF_LIBM" ;;
43     esac
44   fi
45   AC_SUBST([ILOGBF_LIBM])
46 ])
47
48 dnl Test whether ilogbf() works.
49 dnl On OpenBSD 4.9, ilogbf(0.0) is wrong.
50 dnl On NetBSD 5.1, OpenBSD 4.9, ilogbf(Infinity) is wrong.
51 AC_DEFUN([gl_FUNC_ILOGBF_WORKS],
52 [
53   AC_REQUIRE([AC_PROG_CC])
54   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
55   AC_CACHE_CHECK([whether ilogbf works], [gl_cv_func_ilogbf_works],
56     [
57       AC_RUN_IFELSE(
58         [AC_LANG_SOURCE([[
59 #include <limits.h>
60 #include <math.h>
61 /* Provide FP_ILOGB0, FP_ILOGBNAN, like in math.in.h.  */
62 #if !(defined FP_ILOGB0 && defined FP_ILOGBNAN)
63 # if defined __NetBSD__ || defined __sgi
64   /* NetBSD, IRIX 6.5: match what ilogbf() does */
65 #  define FP_ILOGB0   INT_MIN
66 #  define FP_ILOGBNAN INT_MIN
67 # elif defined _AIX
68   /* AIX 5.1: match what ilogbf() does in AIX >= 5.2 */
69 #  define FP_ILOGB0   INT_MIN
70 #  define FP_ILOGBNAN INT_MAX
71 # elif defined __sun
72   /* Solaris 9: match what ilogbf() does */
73 #  define FP_ILOGB0   (- INT_MAX)
74 #  define FP_ILOGBNAN INT_MAX
75 # endif
76 #endif
77 volatile float x;
78 static float zero;
79 static int dummy (float x) { return 0; }
80 int main (int argc, char *argv[])
81 {
82   int (*my_ilogbf) (float) = argc ? ilogbf : dummy;
83   int result = 0;
84   /* This test fails on OpenBSD 4.9.  */
85   {
86     x = 0.0f;
87     if (my_ilogbf (x) != FP_ILOGB0)
88       result |= 1;
89   }
90   /* This test fails on NetBSD 5.1, OpenBSD 4.9.  */
91   {
92     x = 1.0f / zero;
93     if (my_ilogbf (x) != INT_MAX)
94       result |= 2;
95   }
96   return result;
97 }
98 ]])],
99         [gl_cv_func_ilogbf_works=yes],
100         [gl_cv_func_ilogbf_works=no],
101         [case "$host_os" in
102            openbsd* | netbsd*) gl_cv_func_ilogbf_works="guessing no";;
103            *)                  gl_cv_func_ilogbf_works="guessing yes";;
104          esac
105         ])
106     ])
107 ])