update NEWS.stable
[gnulib.git] / m4 / log2f.m4
1 # log2f.m4 serial 2
2 dnl Copyright (C) 2010-2012 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_CACHE_CHECK([whether log2f works according to ISO C 99 with IEC 60559],
42           [gl_cv_func_log2f_ieee],
43           [
44             save_LIBS="$LIBS"
45             LIBS="$LIBS $LOG2F_LIBM"
46             AC_RUN_IFELSE(
47               [AC_LANG_SOURCE([[
48 #ifndef __NO_MATH_INLINES
49 # define __NO_MATH_INLINES 1 /* for glibc */
50 #endif
51 #include <math.h>
52 #ifndef log2f /* for Cygwin 1.7.x */
53 extern
54 #ifdef __cplusplus
55 "C"
56 #endif
57 float log2f (float);
58 #endif
59 /* Compare two numbers with ==.
60    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
61    'x == x' test.  */
62 static int
63 numeric_equal (float x, float y)
64 {
65   return x == y;
66 }
67 static float dummy (float x) { return 0; }
68 int main (int argc, char *argv[])
69 {
70   float (*my_log2f) (float) = argc ? log2f : dummy;
71   /* Test log2f(negative).
72      This test fails on NetBSD 5.1 and Solaris 11 2011-11.  */
73   float y = my_log2f (-1.0f);
74   if (numeric_equal (y, y))
75     return 1;
76   return 0;
77 }
78               ]])],
79               [gl_cv_func_log2f_ieee=yes],
80               [gl_cv_func_log2f_ieee=no],
81               [gl_cv_func_log2f_ieee="guessing no"])
82             LIBS="$save_LIBS"
83           ])
84         case "$gl_cv_func_log2f_ieee" in
85           *yes) ;;
86           *) REPLACE_LOG2F=1 ;;
87         esac
88       fi
89     ])
90   else
91     HAVE_LOG2F=0
92     HAVE_DECL_LOG2F=0
93   fi
94   if test $HAVE_LOG2F = 0 || test $REPLACE_LOG2F = 1; then
95     dnl Find libraries needed to link lib/log2f.c.
96     if test $ac_cv_func_log2 = yes; then
97       AC_DEFINE([HAVE_LOG2], [1],
98         [Define to 1 if the log2() function is available in libc or libm.])
99       LOG2F_LIBM="$LOG2_LIBM"
100     else
101       AC_REQUIRE([gl_FUNC_ISNANF])
102       AC_REQUIRE([gl_FUNC_FREXPF])
103       AC_REQUIRE([gl_FUNC_LOGF])
104       LOG2F_LIBM=
105       dnl Append $ISNANF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
106       case " $LOG2F_LIBM " in
107         *" $ISNANF_LIBM "*) ;;
108         *) LOG2F_LIBM="$LOG2F_LIBM $ISNANF_LIBM" ;;
109       esac
110       dnl Append $FREXPF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
111       case " $LOG2F_LIBM " in
112         *" $FREXPF_LIBM "*) ;;
113         *) LOG2F_LIBM="$LOG2F_LIBM $FREXPF_LIBM" ;;
114       esac
115       dnl Append $LOGF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
116       case " $LOG2F_LIBM " in
117         *" $LOGF_LIBM "*) ;;
118         *) LOG2F_LIBM="$LOG2F_LIBM $LOGF_LIBM" ;;
119       esac
120     fi
121   fi
122 ])
123
124 dnl Test whether log2() works.
125 dnl On OSF/1 5.1, log2f(-0.0f) is NaN.
126 dnl On Cygwin 1.7.9, log2f(2^13) is not exactly 13.
127 AC_DEFUN([gl_FUNC_LOG2F_WORKS],
128 [
129   AC_REQUIRE([AC_PROG_CC])
130   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
131   AC_CACHE_CHECK([whether log2f works], [gl_cv_func_log2f_works],
132     [
133       AC_RUN_IFELSE(
134         [AC_LANG_SOURCE([[
135 #include <math.h>
136 #ifndef log2f /* for Cygwin 1.7.x */
137 extern
138 #ifdef __cplusplus
139 "C"
140 #endif
141 float log2f (float);
142 #endif
143 volatile float x;
144 volatile float y;
145 int main ()
146 {
147   int result = 0;
148   /* This test fails on OSF/1 5.1.  */
149   x = -0.0f;
150   y = log2f (x);
151   if (!(y + y == y))
152     result |= 1;
153   /* This test fails on Cygwin 1.7.9.  */
154   x = 8192.0f;
155   y = log2f (x);
156   if (!(y == 13.0f))
157     result |= 2;
158   return result;
159 }
160 ]])],
161         [gl_cv_func_log2f_works=yes],
162         [gl_cv_func_log2f_works=no],
163         [case "$host_os" in
164            cygwin* | osf*) gl_cv_func_log2f_works="guessing no";;
165            *)              gl_cv_func_log2f_works="guessing yes";;
166          esac
167         ])
168     ])
169 ])