4ff32d8da15a5b94788cb78d7d5a4517e3eea6da
[gnulib.git] / m4 / log2f.m4
1 # log2f.m4 serial 1
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   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   AC_REQUIRE([gl_FUNC_LOG2])
11
12   dnl Persuade glibc <math.h> to declare log2f().
13   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14
15   dnl Determine LOG2F_LIBM.
16   gl_COMMON_DOUBLE_MATHFUNC([log2f])
17
18   dnl Test whether log2f() exists.
19   save_LIBS="$LIBS"
20   LIBS="$LIBS $LOG2F_LIBM"
21   AC_CHECK_FUNCS([log2f])
22   LIBS="$save_LIBS"
23   if test $ac_cv_func_log2f = yes; then
24     HAVE_LOG2F=1
25     dnl Also check whether it's declared.
26     dnl IRIX 6.5 has log2f() in libm but doesn't declare it in <math.h>.
27     AC_CHECK_DECL([log2f], , [HAVE_DECL_LOG2F=0], [[#include <math.h>]])
28
29     save_LIBS="$LIBS"
30     LIBS="$LIBS $LOG2F_LIBM"
31     gl_FUNC_LOG2F_WORKS
32     LIBS="$save_LIBS"
33     case "$gl_cv_func_log2f_works" in
34       *yes) ;;
35       *) REPLACE_LOG2F=1 ;;
36     esac
37   else
38     HAVE_LOG2F=0
39     HAVE_DECL_LOG2F=0
40   fi
41   if test $HAVE_LOG2F = 0 || test $REPLACE_LOG2F = 1; then
42     dnl Find libraries needed to link lib/log2f.c.
43     if test $ac_cv_func_log2 = yes; then
44       AC_DEFINE([HAVE_LOG2], [1],
45         [Define to 1 if the log2() function is available in libc or libm.])
46       LOG2F_LIBM="$LOG2_LIBM"
47     else
48       AC_REQUIRE([gl_FUNC_ISNANF])
49       AC_REQUIRE([gl_FUNC_FREXPF])
50       AC_REQUIRE([gl_FUNC_LOGF])
51       LOG2F_LIBM=
52       dnl Append $ISNANF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
53       case " $LOG2F_LIBM " in
54         *" $ISNANF_LIBM "*) ;;
55         *) LOG2F_LIBM="$LOG2F_LIBM $ISNANF_LIBM" ;;
56       esac
57       dnl Append $FREXPF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
58       case " $LOG2F_LIBM " in
59         *" $FREXPF_LIBM "*) ;;
60         *) LOG2F_LIBM="$LOG2F_LIBM $FREXPF_LIBM" ;;
61       esac
62       dnl Append $LOGF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
63       case " $LOG2F_LIBM " in
64         *" $LOGF_LIBM "*) ;;
65         *) LOG2F_LIBM="$LOG2F_LIBM $LOGF_LIBM" ;;
66       esac
67     fi
68   fi
69 ])
70
71 dnl Test whether log2() works.
72 dnl On OSF/1 5.1, log2f(-0.0f) is NaN.
73 dnl On Cygwin 1.7.9, log2f(2^13) is not exactly 13.
74 AC_DEFUN([gl_FUNC_LOG2F_WORKS],
75 [
76   AC_REQUIRE([AC_PROG_CC])
77   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
78   AC_CACHE_CHECK([whether log2f works], [gl_cv_func_log2f_works],
79     [
80       AC_RUN_IFELSE(
81         [AC_LANG_SOURCE([[
82 #include <math.h>
83 #ifndef log2f /* for Cygwin 1.7.x */
84 extern
85 #ifdef __cplusplus
86 "C"
87 #endif
88 float log2f (float);
89 #endif
90 volatile float x;
91 volatile float y;
92 int main ()
93 {
94   int result = 0;
95   /* This test fails on OSF/1 5.1.  */
96   x = -0.0f;
97   y = log2f (x);
98   if (!(y + y == y))
99     result |= 1;
100   /* This test fails on Cygwin 1.7.9.  */
101   x = 8192.0f;
102   y = log2f (x);
103   if (!(y == 13.0f))
104     result |= 2;
105   return result;
106 }
107 ]])],
108         [gl_cv_func_log2f_works=yes],
109         [gl_cv_func_log2f_works=no],
110         [case "$host_os" in
111            cygwin* | osf*) gl_cv_func_log2f_works="guessing no";;
112            *)              gl_cv_func_log2f_works="guessing yes";;
113          esac
114         ])
115     ])
116 ])