maint: update copyright
[gnulib.git] / m4 / log2f.m4
1 # log2f.m4 serial 3
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_LOG2F],
8 [
9   m4_divert_text([DEFAULTS], [gl_log2f_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_FUNC_LOG2])
12
13   dnl Persuade glibc <math.h> to declare log2f().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15
16   dnl Determine LOG2F_LIBM.
17   gl_COMMON_DOUBLE_MATHFUNC([log2f])
18
19   dnl Test whether log2f() exists.
20   save_LIBS="$LIBS"
21   LIBS="$LIBS $LOG2F_LIBM"
22   AC_CHECK_FUNCS([log2f])
23   LIBS="$save_LIBS"
24   if test $ac_cv_func_log2f = yes; then
25     HAVE_LOG2F=1
26     dnl Also check whether it's declared.
27     dnl IRIX 6.5 has log2f() in libm but doesn't declare it in <math.h>.
28     AC_CHECK_DECL([log2f], , [HAVE_DECL_LOG2F=0], [[#include <math.h>]])
29
30     save_LIBS="$LIBS"
31     LIBS="$LIBS $LOG2F_LIBM"
32     gl_FUNC_LOG2F_WORKS
33     LIBS="$save_LIBS"
34     case "$gl_cv_func_log2f_works" in
35       *yes) ;;
36       *) REPLACE_LOG2F=1 ;;
37     esac
38
39     m4_ifdef([gl_FUNC_LOG2F_IEEE], [
40       if test $gl_log2f_required = ieee && test $REPLACE_LOG2F = 0; then
41         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
42         AC_CACHE_CHECK([whether log2f works according to ISO C 99 with IEC 60559],
43           [gl_cv_func_log2f_ieee],
44           [
45             save_LIBS="$LIBS"
46             LIBS="$LIBS $LOG2F_LIBM"
47             AC_RUN_IFELSE(
48               [AC_LANG_SOURCE([[
49 #ifndef __NO_MATH_INLINES
50 # define __NO_MATH_INLINES 1 /* for glibc */
51 #endif
52 #include <math.h>
53 #ifndef log2f /* for Cygwin 1.7.x */
54 extern
55 #ifdef __cplusplus
56 "C"
57 #endif
58 float log2f (float);
59 #endif
60 /* Compare two numbers with ==.
61    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
62    'x == x' test.  */
63 static int
64 numeric_equal (float x, float y)
65 {
66   return x == y;
67 }
68 static float dummy (float x) { return 0; }
69 int main (int argc, char *argv[])
70 {
71   float (*my_log2f) (float) = argc ? log2f : dummy;
72   /* Test log2f(negative).
73      This test fails on NetBSD 5.1 and Solaris 11 2011-11.  */
74   float y = my_log2f (-1.0f);
75   if (numeric_equal (y, y))
76     return 1;
77   return 0;
78 }
79               ]])],
80               [gl_cv_func_log2f_ieee=yes],
81               [gl_cv_func_log2f_ieee=no],
82               [case "$host_os" in
83                          # Guess yes on glibc systems.
84                  *-gnu*) gl_cv_func_log2f_ieee="guessing yes" ;;
85                          # If we don't know, assume the worst.
86                  *)      gl_cv_func_log2f_ieee="guessing no" ;;
87                esac
88               ])
89             LIBS="$save_LIBS"
90           ])
91         case "$gl_cv_func_log2f_ieee" in
92           *yes) ;;
93           *) REPLACE_LOG2F=1 ;;
94         esac
95       fi
96     ])
97   else
98     HAVE_LOG2F=0
99     HAVE_DECL_LOG2F=0
100   fi
101   if test $HAVE_LOG2F = 0 || test $REPLACE_LOG2F = 1; then
102     dnl Find libraries needed to link lib/log2f.c.
103     if test $ac_cv_func_log2 = yes; then
104       AC_DEFINE([HAVE_LOG2], [1],
105         [Define to 1 if the log2() function is available in libc or libm.])
106       LOG2F_LIBM="$LOG2_LIBM"
107     else
108       AC_REQUIRE([gl_FUNC_ISNANF])
109       AC_REQUIRE([gl_FUNC_FREXPF])
110       AC_REQUIRE([gl_FUNC_LOGF])
111       LOG2F_LIBM=
112       dnl Append $ISNANF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
113       case " $LOG2F_LIBM " in
114         *" $ISNANF_LIBM "*) ;;
115         *) LOG2F_LIBM="$LOG2F_LIBM $ISNANF_LIBM" ;;
116       esac
117       dnl Append $FREXPF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
118       case " $LOG2F_LIBM " in
119         *" $FREXPF_LIBM "*) ;;
120         *) LOG2F_LIBM="$LOG2F_LIBM $FREXPF_LIBM" ;;
121       esac
122       dnl Append $LOGF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
123       case " $LOG2F_LIBM " in
124         *" $LOGF_LIBM "*) ;;
125         *) LOG2F_LIBM="$LOG2F_LIBM $LOGF_LIBM" ;;
126       esac
127     fi
128   fi
129 ])
130
131 dnl Test whether log2() works.
132 dnl On OSF/1 5.1, log2f(-0.0f) is NaN.
133 dnl On Cygwin 1.7.9, log2f(2^13) is not exactly 13.
134 AC_DEFUN([gl_FUNC_LOG2F_WORKS],
135 [
136   AC_REQUIRE([AC_PROG_CC])
137   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
138   AC_CACHE_CHECK([whether log2f works], [gl_cv_func_log2f_works],
139     [
140       AC_RUN_IFELSE(
141         [AC_LANG_SOURCE([[
142 #include <math.h>
143 #ifndef log2f /* for Cygwin 1.7.x */
144 extern
145 #ifdef __cplusplus
146 "C"
147 #endif
148 float log2f (float);
149 #endif
150 volatile float x;
151 volatile float y;
152 int main ()
153 {
154   int result = 0;
155   /* This test fails on OSF/1 5.1.  */
156   x = -0.0f;
157   y = log2f (x);
158   if (!(y + y == y))
159     result |= 1;
160   /* This test fails on Cygwin 1.7.9.  */
161   x = 8192.0f;
162   y = log2f (x);
163   if (!(y == 13.0f))
164     result |= 2;
165   return result;
166 }
167 ]])],
168         [gl_cv_func_log2f_works=yes],
169         [gl_cv_func_log2f_works=no],
170         [case "$host_os" in
171            cygwin* | osf*) gl_cv_func_log2f_works="guessing no";;
172            *)              gl_cv_func_log2f_works="guessing yes";;
173          esac
174         ])
175     ])
176 ])