maint: update copyright
[gnulib.git] / m4 / logf.m4
1 # logf.m4 serial 6
2 dnl Copyright (C) 2011-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_LOGF],
8 [
9   m4_divert_text([DEFAULTS], [gl_logf_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_FUNC_LOG])
12
13   dnl Persuade glibc <math.h> to declare logf().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15
16   dnl Test whether logf() exists. Assume that logf(), if it exists, is
17   dnl defined in the same library as log().
18   save_LIBS="$LIBS"
19   LIBS="$LIBS $LOG_LIBM"
20   AC_CHECK_FUNCS([logf])
21   LIBS="$save_LIBS"
22   if test $ac_cv_func_logf = yes; then
23     LOGF_LIBM="$LOG_LIBM"
24
25     save_LIBS="$LIBS"
26     LIBS="$LIBS $LOGF_LIBM"
27     gl_FUNC_LOGF_WORKS
28     LIBS="$save_LIBS"
29     case "$gl_cv_func_logf_works" in
30       *yes) ;;
31       *) REPLACE_LOGF=1 ;;
32     esac
33
34     m4_ifdef([gl_FUNC_LOGF_IEEE], [
35       if test $gl_logf_required = ieee && test $REPLACE_LOGF = 0; then
36         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
37         AC_CACHE_CHECK([whether logf works according to ISO C 99 with IEC 60559],
38           [gl_cv_func_logf_ieee],
39           [
40             save_LIBS="$LIBS"
41             LIBS="$LIBS $LOGF_LIBM"
42             AC_RUN_IFELSE(
43               [AC_LANG_SOURCE([[
44 #ifndef __NO_MATH_INLINES
45 # define __NO_MATH_INLINES 1 /* for glibc */
46 #endif
47 #include <math.h>
48 /* Compare two numbers with ==.
49    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
50    'x == x' test.  */
51 static int
52 numeric_equal (float x, float y)
53 {
54   return x == y;
55 }
56 static float dummy (float x) { return 0; }
57 int main (int argc, char *argv[])
58 {
59   float (*my_logf) (float) = argc ? logf : dummy;
60   /* Test logf(negative).
61      This test fails on NetBSD 5.1.  */
62   float y = my_logf (-1.0f);
63   if (numeric_equal (y, y))
64     return 1;
65   return 0;
66 }
67               ]])],
68               [gl_cv_func_logf_ieee=yes],
69               [gl_cv_func_logf_ieee=no],
70               [case "$host_os" in
71                          # Guess yes on glibc systems.
72                  *-gnu*) gl_cv_func_logf_ieee="guessing yes" ;;
73                          # If we don't know, assume the worst.
74                  *)      gl_cv_func_logf_ieee="guessing no" ;;
75                esac
76               ])
77             LIBS="$save_LIBS"
78           ])
79         case "$gl_cv_func_logf_ieee" in
80           *yes) ;;
81           *) REPLACE_LOGF=1 ;;
82         esac
83       fi
84     ])
85   else
86     HAVE_LOGF=0
87   fi
88   if test $HAVE_LOGF = 0 || test $REPLACE_LOGF = 1; then
89     dnl Find libraries needed to link lib/logf.c.
90     if test $HAVE_LOGF = 0; then
91       LOGF_LIBM="$LOG_LIBM"
92     fi
93   fi
94   AC_SUBST([LOGF_LIBM])
95 ])
96
97 dnl Test whether logf() works.
98 dnl On OSF/1 5.1, logf(-0.0f) is NaN.
99 AC_DEFUN([gl_FUNC_LOGF_WORKS],
100 [
101   AC_REQUIRE([AC_PROG_CC])
102   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
103   AC_CACHE_CHECK([whether logf works], [gl_cv_func_logf_works],
104     [
105       AC_RUN_IFELSE(
106         [AC_LANG_SOURCE([[
107 #include <math.h>
108 volatile float x;
109 float y;
110 int main ()
111 {
112   x = -0.0f;
113   y = logf (x);
114   if (!(y + y == y))
115     return 1;
116   return 0;
117 }
118 ]])],
119         [gl_cv_func_logf_works=yes],
120         [gl_cv_func_logf_works=no],
121         [case "$host_os" in
122            osf*) gl_cv_func_logf_works="guessing no";;
123            *)    gl_cv_func_logf_works="guessing yes";;
124          esac
125         ])
126     ])
127 ])