update copyright
[gnulib.git] / m4 / log.m4
1 # log.m4 serial 3
2 dnl Copyright (C) 2011-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_LOG],
8 [
9   m4_divert_text([DEFAULTS], [gl_log_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11
12   dnl Determine LOG_LIBM.
13   gl_COMMON_DOUBLE_MATHFUNC([log])
14
15   save_LIBS="$LIBS"
16   LIBS="$LIBS $LOG_LIBM"
17   gl_FUNC_LOG_WORKS
18   LIBS="$save_LIBS"
19   case "$gl_cv_func_log_works" in
20     *yes) ;;
21     *) REPLACE_LOG=1 ;;
22   esac
23
24   m4_ifdef([gl_FUNC_LOG_IEEE], [
25     if test $gl_log_required = ieee && test $REPLACE_LOG = 0; then
26       AC_CACHE_CHECK([whether log works according to ISO C 99 with IEC 60559],
27         [gl_cv_func_log_ieee],
28         [
29           save_LIBS="$LIBS"
30           LIBS="$LIBS $LOG_LIBM"
31           AC_RUN_IFELSE(
32             [AC_LANG_SOURCE([[
33 #ifndef __NO_MATH_INLINES
34 # define __NO_MATH_INLINES 1 /* for glibc */
35 #endif
36 #include <math.h>
37 /* Compare two numbers with ==.
38    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
39    'x == x' test.  */
40 static int
41 numeric_equal (double x, double y)
42 {
43   return x == y;
44 }
45 static double dummy (double x) { return 0; }
46 int main (int argc, char *argv[])
47 {
48   double (*my_log) (double) = argc ? log : dummy;
49   /* Test log(negative).
50      This test fails on NetBSD 5.1, Solaris 11 2011-11.  */
51   double y = my_log (-1.0);
52   if (numeric_equal (y, y))
53     return 1;
54   return 0;
55 }
56             ]])],
57             [gl_cv_func_log_ieee=yes],
58             [gl_cv_func_log_ieee=no],
59             [gl_cv_func_log_ieee="guessing no"])
60           LIBS="$save_LIBS"
61         ])
62       case "$gl_cv_func_log_ieee" in
63         *yes) ;;
64         *) REPLACE_LOG=1 ;;
65       esac
66     fi
67   ])
68 ])
69
70 dnl Test whether log() works.
71 dnl On OSF/1 5.1, log(-0.0) is NaN.
72 AC_DEFUN([gl_FUNC_LOG_WORKS],
73 [
74   AC_REQUIRE([AC_PROG_CC])
75   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
76   AC_CACHE_CHECK([whether log works], [gl_cv_func_log_works],
77     [
78       AC_RUN_IFELSE(
79         [AC_LANG_SOURCE([[
80 #include <math.h>
81 volatile double x;
82 double y;
83 int main ()
84 {
85   x = -0.0;
86   y = log (x);
87   if (!(y + y == y))
88     return 1;
89   return 0;
90 }
91 ]])],
92         [gl_cv_func_log_works=yes],
93         [gl_cv_func_log_works=no],
94         [case "$host_os" in
95            osf*) gl_cv_func_log_works="guessing no";;
96            *)    gl_cv_func_log_works="guessing yes";;
97          esac
98         ])
99     ])
100 ])