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