*printf-posix-tests: Strengthen tests.
[gnulib.git] / m4 / log.m4
blob3e4e7d50e34d6d8582aba3fc49441f25a3e88ab0
1 # log.m4
2 # serial 14
3 dnl Copyright (C) 2011-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_LOG],
10   m4_divert_text([DEFAULTS], [gl_log_required=plain])
11   AC_REQUIRE([gl_MATH_H_DEFAULTS])
13   dnl Determine LOG_LIBM.
14   gl_COMMON_DOUBLE_MATHFUNC([log])
16   saved_LIBS="$LIBS"
17   LIBS="$LIBS $LOG_LIBM"
18   gl_FUNC_LOG_WORKS
19   LIBS="$saved_LIBS"
20   case "$gl_cv_func_log_works" in
21     *yes) ;;
22     *) REPLACE_LOG=1 ;;
23   esac
25   m4_ifdef([gl_FUNC_LOG_IEEE], [
26     if test $gl_log_required = ieee && test $REPLACE_LOG = 0; then
27       AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
28       AC_CACHE_CHECK([whether log works according to ISO C 99 with IEC 60559],
29         [gl_cv_func_log_ieee],
30         [
31           saved_LIBS="$LIBS"
32           LIBS="$LIBS $LOG_LIBM"
33           AC_RUN_IFELSE(
34             [AC_LANG_SOURCE([[
35 #ifndef __NO_MATH_INLINES
36 # define __NO_MATH_INLINES 1 /* for glibc */
37 #endif
38 #include <math.h>
39 /* Compare two numbers with ==.
40    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
41    'x == x' test.  */
42 static int
43 numeric_equal (double x, double y)
45   return x == y;
47 static double dummy (double x) { return 0; }
48 int main (int argc, char *argv[])
50   double (* volatile my_log) (double) = argc ? log : dummy;
51   /* Test log(negative).
52      This test fails on NetBSD 5.1, Solaris 11.4.  */
53   double y = my_log (-1.0);
54   if (numeric_equal (y, y))
55     return 1;
56   return 0;
58             ]])],
59             [gl_cv_func_log_ieee=yes],
60             [gl_cv_func_log_ieee=no],
61             [case "$host_os" in
62                                    # Guess yes on glibc systems.
63                *-gnu* | gnu*)      gl_cv_func_log_ieee="guessing yes" ;;
64                                    # Guess yes on musl systems.
65                *-musl* | midipix*) gl_cv_func_log_ieee="guessing yes" ;;
66                                    # Guess yes on native Windows.
67                mingw* | windows*)  gl_cv_func_log_ieee="guessing yes" ;;
68                                    # If we don't know, obey --enable-cross-guesses.
69                *)                  gl_cv_func_log_ieee="$gl_cross_guess_normal" ;;
70              esac
71             ])
72           LIBS="$saved_LIBS"
73         ])
74       case "$gl_cv_func_log_ieee" in
75         *yes) ;;
76         *) REPLACE_LOG=1 ;;
77       esac
78     fi
79   ])
82 dnl Test whether log() works.
83 dnl On OSF/1 5.1, log(-0.0) is NaN.
84 AC_DEFUN([gl_FUNC_LOG_WORKS],
86   AC_REQUIRE([AC_PROG_CC])
87   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
88   AC_CACHE_CHECK([whether log works], [gl_cv_func_log_works],
89     [
90       AC_RUN_IFELSE(
91         [AC_LANG_SOURCE([[
92 #include <math.h>
93 volatile double x;
94 double y;
95 int main ()
97   x = -0.0;
98   y = log (x);
99   if (!(y + y == y))
100     return 1;
101   return 0;
103 ]])],
104         [gl_cv_func_log_works=yes],
105         [gl_cv_func_log_works=no],
106         [case "$host_os" in
107            osf*)              gl_cv_func_log_works="guessing no" ;;
108                               # Guess yes on native Windows.
109            mingw* | windows*) gl_cv_func_log_works="guessing yes" ;;
110            *)                 gl_cv_func_log_works="guessing yes" ;;
111          esac
112         ])
113     ])