announce-gen: avoid failure due to lack of Digest::SHA1
[gnulib.git] / m4 / log2.m4
1 # log2.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_LOG2],
8 [
9   m4_divert_text([DEFAULTS], [gl_log2_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11
12   dnl Persuade glibc <math.h> to declare log2().
13   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14
15   dnl Determine LOG2_LIBM.
16   gl_COMMON_DOUBLE_MATHFUNC([log2])
17
18   dnl Test whether log2() exists.
19   save_LIBS="$LIBS"
20   LIBS="$LIBS $LOG2_LIBM"
21   AC_CHECK_FUNCS([log2])
22   LIBS="$save_LIBS"
23   if test $ac_cv_func_log2 = yes; then
24     HAVE_LOG2=1
25     dnl Also check whether it's declared.
26     dnl IRIX 6.5 has log2() in libm but doesn't declare it in <math.h>.
27     AC_CHECK_DECL([log2], , [HAVE_DECL_LOG2=0], [[#include <math.h>]])
28
29     save_LIBS="$LIBS"
30     LIBS="$LIBS $LOG2_LIBM"
31     gl_FUNC_LOG2_WORKS
32     LIBS="$save_LIBS"
33     case "$gl_cv_func_log2_works" in
34       *yes) ;;
35       *) REPLACE_LOG2=1 ;;
36     esac
37
38     m4_ifdef([gl_FUNC_LOG2_IEEE], [
39       if test $gl_log2_required = ieee && test $REPLACE_LOG2 = 0; then
40         AC_CACHE_CHECK([whether log2 works according to ISO C 99 with IEC 60559],
41           [gl_cv_func_log2_ieee],
42           [
43             save_LIBS="$LIBS"
44             LIBS="$LIBS $LOG2_LIBM"
45             AC_RUN_IFELSE(
46               [AC_LANG_SOURCE([[
47 #ifndef __NO_MATH_INLINES
48 # define __NO_MATH_INLINES 1 /* for glibc */
49 #endif
50 #include <math.h>
51 #ifndef log2 /* for Cygwin 1.7.x */
52 extern
53 #ifdef __cplusplus
54 "C"
55 #endif
56 double log2 (double);
57 #endif
58 /* Compare two numbers with ==.
59    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
60    'x == x' test.  */
61 static int
62 numeric_equal (double x, double y)
63 {
64   return x == y;
65 }
66 static double dummy (double x) { return 0; }
67 int main (int argc, char *argv[])
68 {
69   double (*my_log2) (double) = argc ? log2 : dummy;
70   /* Test log2(negative).
71      This test fails on NetBSD 5.1 and Solaris 11 2011-11.  */
72   double y = my_log2 (-1.0);
73   if (numeric_equal (y, y))
74     return 1;
75   return 0;
76 }
77               ]])],
78               [gl_cv_func_log2_ieee=yes],
79               [gl_cv_func_log2_ieee=no],
80               [gl_cv_func_log2_ieee="guessing no"])
81             LIBS="$save_LIBS"
82           ])
83         case "$gl_cv_func_log2_ieee" in
84           *yes) ;;
85           *) REPLACE_LOG2=1 ;;
86         esac
87       fi
88     ])
89   else
90     HAVE_LOG2=0
91     HAVE_DECL_LOG2=0
92   fi
93   if test $HAVE_LOG2 = 0 || test $REPLACE_LOG2 = 1; then
94     dnl Find libraries needed to link lib/log2.c.
95     AC_REQUIRE([gl_FUNC_ISNAND])
96     AC_REQUIRE([gl_FUNC_FREXP])
97     AC_REQUIRE([gl_FUNC_LOG])
98     LOG2_LIBM=
99     dnl Append $ISNAND_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
100     case " $LOG2_LIBM " in
101       *" $ISNAND_LIBM "*) ;;
102       *) LOG2_LIBM="$LOG2_LIBM $ISNAND_LIBM" ;;
103     esac
104     dnl Append $FREXP_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
105     case " $LOG2_LIBM " in
106       *" $FREXP_LIBM "*) ;;
107       *) LOG2_LIBM="$LOG2_LIBM $FREXP_LIBM" ;;
108     esac
109     dnl Append $LOG_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
110     case " $LOG2_LIBM " in
111       *" $LOG_LIBM "*) ;;
112       *) LOG2_LIBM="$LOG2_LIBM $LOG_LIBM" ;;
113     esac
114   fi
115 ])
116
117 dnl Test whether log2() works.
118 dnl On OSF/1 5.1, log2(-0.0) is NaN.
119 dnl On Cygwin 1.7.9, log2(2^29) is not exactly 29.
120 AC_DEFUN([gl_FUNC_LOG2_WORKS],
121 [
122   AC_REQUIRE([AC_PROG_CC])
123   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
124   AC_CACHE_CHECK([whether log2 works], [gl_cv_func_log2_works],
125     [
126       AC_RUN_IFELSE(
127         [AC_LANG_SOURCE([[
128 #include <math.h>
129 #ifndef log2 /* for Cygwin 1.7.x */
130 extern
131 #ifdef __cplusplus
132 "C"
133 #endif
134 double log2 (double);
135 #endif
136 volatile double x;
137 volatile double y;
138 int main ()
139 {
140   int result = 0;
141   /* This test fails on OSF/1 5.1.  */
142   x = -0.0;
143   y = log2 (x);
144   if (!(y + y == y))
145     result |= 1;
146   /* This test fails on Cygwin 1.7.9.  */
147   x = 536870912.0;
148   y = log2 (x);
149   if (!(y == 29.0))
150     result |= 2;
151   return result;
152 }
153 ]])],
154         [gl_cv_func_log2_works=yes],
155         [gl_cv_func_log2_works=no],
156         [case "$host_os" in
157            cygwin* | osf*) gl_cv_func_log2_works="guessing no";;
158            *)              gl_cv_func_log2_works="guessing yes";;
159          esac
160         ])
161     ])
162 ])