immutable: Add tests.
[gnulib.git] / m4 / log10f.m4
blob4ba372f86d4b58c451be9921fdeb6a288d9a319c
1 # log10f.m4 serial 12
2 dnl Copyright (C) 2011-2021 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.
7 AC_DEFUN([gl_FUNC_LOG10F],
9   m4_divert_text([DEFAULTS], [gl_log10f_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_FUNC_LOG10])
13   dnl Persuade glibc <math.h> to declare log10f().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16   dnl Test whether log10f() exists. Assume that log10f(), if it exists, is
17   dnl defined in the same library as log10().
18   save_LIBS="$LIBS"
19   LIBS="$LIBS $LOG10_LIBM"
20   AC_CHECK_FUNCS([log10f])
21   LIBS="$save_LIBS"
22   if test $ac_cv_func_log10f = yes; then
23     LOG10F_LIBM="$LOG10_LIBM"
25     save_LIBS="$LIBS"
26     LIBS="$LIBS $LOG10F_LIBM"
27     gl_FUNC_LOG10F_WORKS
28     LIBS="$save_LIBS"
29     case "$gl_cv_func_log10f_works" in
30       *yes) ;;
31       *) REPLACE_LOG10F=1 ;;
32     esac
34     m4_ifdef([gl_FUNC_LOG10F_IEEE], [
35       if test $gl_log10f_required = ieee && test $REPLACE_LOG10F = 0; then
36         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
37         AC_CACHE_CHECK([whether log10f works according to ISO C 99 with IEC 60559],
38           [gl_cv_func_log10f_ieee],
39           [
40             save_LIBS="$LIBS"
41             LIBS="$LIBS $LOG10F_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)
54   return x == y;
56 static float dummy (float x) { return 0; }
57 int main (int argc, char *argv[])
59   float (* volatile my_log10f) (float) = argc ? log10f : dummy;
60   /* Test log10f(negative).
61      This test fails on NetBSD 5.1.  */
62   float y = my_log10f (-1.0f);
63   if (numeric_equal (y, y))
64     return 1;
65   return 0;
67               ]])],
68               [gl_cv_func_log10f_ieee=yes],
69               [gl_cv_func_log10f_ieee=no],
70               [case "$host_os" in
71                                 # Guess yes on glibc systems.
72                  *-gnu* | gnu*) gl_cv_func_log10f_ieee="guessing yes" ;;
73                                 # Guess yes on musl systems.
74                  *-musl*)       gl_cv_func_log10f_ieee="guessing yes" ;;
75                                 # Guess yes on native Windows.
76                  mingw*)        gl_cv_func_log10f_ieee="guessing yes" ;;
77                                 # If we don't know, obey --enable-cross-guesses.
78                  *)             gl_cv_func_log10f_ieee="$gl_cross_guess_normal" ;;
79                esac
80               ])
81             LIBS="$save_LIBS"
82           ])
83         case "$gl_cv_func_log10f_ieee" in
84           *yes) ;;
85           *) REPLACE_LOG10F=1 ;;
86         esac
87       fi
88     ])
89   else
90     HAVE_LOG10F=0
91     dnl If the function is declared but does not appear to exist, it may be
92     dnl defined as an inline function. In order to avoid a conflict, we have
93     dnl to define rpl_log10f, not log10f.
94     AC_CHECK_DECLS([log10f], [REPLACE_LOG10F=1], , [[#include <math.h>]])
95   fi
96   if test $HAVE_LOG10F = 0 || test $REPLACE_LOG10F = 1; then
97     dnl Find libraries needed to link lib/log10f.c.
98     if test $HAVE_LOG10F = 0; then
99       LOG10F_LIBM="$LOG10_LIBM"
100     fi
101   fi
102   AC_SUBST([LOG10F_LIBM])
105 dnl Test whether log10f() works.
106 dnl On OSF/1 5.1, log10f(-0.0f) is NaN.
107 AC_DEFUN([gl_FUNC_LOG10F_WORKS],
109   AC_REQUIRE([AC_PROG_CC])
110   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
111   AC_CACHE_CHECK([whether log10f works], [gl_cv_func_log10f_works],
112     [
113       AC_RUN_IFELSE(
114         [AC_LANG_SOURCE([[
115 #include <math.h>
116 volatile float x;
117 float y;
118 int main ()
120   x = -0.0f;
121   y = log10f (x);
122   if (!(y + y == y))
123     return 1;
124   return 0;
126 ]])],
127         [gl_cv_func_log10f_works=yes],
128         [gl_cv_func_log10f_works=no],
129         [case "$host_os" in
130            osf*)   gl_cv_func_log10f_works="guessing no" ;;
131                    # Guess yes on native Windows.
132            mingw*) gl_cv_func_log10f_works="guessing yes" ;;
133            *)      gl_cv_func_log10f_works="guessing yes" ;;
134          esac
135         ])
136     ])