immutable: Add tests.
[gnulib.git] / m4 / log2f.m4
blobc1af71d10a25e38a5310060cceabcb54c4542f98
1 # log2f.m4 serial 10
2 dnl Copyright (C) 2010-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_LOG2F],
9   m4_divert_text([DEFAULTS], [gl_log2f_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_FUNC_LOG2])
13   dnl Persuade glibc <math.h> to declare log2f().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16   dnl Determine LOG2F_LIBM.
17   gl_COMMON_DOUBLE_MATHFUNC([log2f])
19   dnl Test whether log2f() exists.
20   save_LIBS="$LIBS"
21   LIBS="$LIBS $LOG2F_LIBM"
22   AC_CHECK_FUNCS([log2f])
23   LIBS="$save_LIBS"
24   if test $ac_cv_func_log2f = yes; then
25     HAVE_LOG2F=1
26     dnl Also check whether it's declared.
27     dnl IRIX 6.5 has log2f() in libm but doesn't declare it in <math.h>.
28     AC_CHECK_DECL([log2f], , [HAVE_DECL_LOG2F=0], [[#include <math.h>]])
30     save_LIBS="$LIBS"
31     LIBS="$LIBS $LOG2F_LIBM"
32     gl_FUNC_LOG2F_WORKS
33     LIBS="$save_LIBS"
34     case "$gl_cv_func_log2f_works" in
35       *yes) ;;
36       *) REPLACE_LOG2F=1 ;;
37     esac
39     m4_ifdef([gl_FUNC_LOG2F_IEEE], [
40       if test $gl_log2f_required = ieee && test $REPLACE_LOG2F = 0; then
41         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
42         AC_CACHE_CHECK([whether log2f works according to ISO C 99 with IEC 60559],
43           [gl_cv_func_log2f_ieee],
44           [
45             save_LIBS="$LIBS"
46             LIBS="$LIBS $LOG2F_LIBM"
47             AC_RUN_IFELSE(
48               [AC_LANG_SOURCE([[
49 #ifndef __NO_MATH_INLINES
50 # define __NO_MATH_INLINES 1 /* for glibc */
51 #endif
52 #include <math.h>
53 #ifndef log2f /* for Cygwin 1.7.x */
54 extern
55 #ifdef __cplusplus
56 "C"
57 #endif
58 float log2f (float);
59 #endif
60 /* Compare two numbers with ==.
61    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
62    'x == x' test.  */
63 static int
64 numeric_equal (float x, float y)
66   return x == y;
68 static float dummy (float x) { return 0; }
69 int main (int argc, char *argv[])
71   float (* volatile my_log2f) (float) = argc ? log2f : dummy;
72   /* Test log2f(negative).
73      This test fails on NetBSD 5.1 and Solaris 10/x86_64.  */
74   float y = my_log2f (-1.0f);
75   if (numeric_equal (y, y))
76     return 1;
77   return 0;
79               ]])],
80               [gl_cv_func_log2f_ieee=yes],
81               [gl_cv_func_log2f_ieee=no],
82               [case "$host_os" in
83                                 # Guess yes on glibc systems.
84                  *-gnu* | gnu*) gl_cv_func_log2f_ieee="guessing yes" ;;
85                                 # Guess yes on musl systems.
86                  *-musl*)       gl_cv_func_log2f_ieee="guessing yes" ;;
87                                 # Guess yes on native Windows.
88                  mingw*)        gl_cv_func_log2f_ieee="guessing yes" ;;
89                                 # If we don't know, obey --enable-cross-guesses.
90                  *)             gl_cv_func_log2f_ieee="$gl_cross_guess_normal" ;;
91                esac
92               ])
93             LIBS="$save_LIBS"
94           ])
95         case "$gl_cv_func_log2f_ieee" in
96           *yes) ;;
97           *) REPLACE_LOG2F=1 ;;
98         esac
99       fi
100     ])
101   else
102     HAVE_LOG2F=0
103     HAVE_DECL_LOG2F=0
104   fi
105   if test $HAVE_LOG2F = 0 || test $REPLACE_LOG2F = 1; then
106     dnl Find libraries needed to link lib/log2f.c.
107     if test $ac_cv_func_log2 = yes; then
108       AC_DEFINE([HAVE_LOG2], [1],
109         [Define to 1 if the log2() function is available in libc or libm.])
110       LOG2F_LIBM="$LOG2_LIBM"
111     else
112       AC_REQUIRE([gl_FUNC_ISNANF])
113       AC_REQUIRE([gl_FUNC_FREXPF])
114       AC_REQUIRE([gl_FUNC_LOGF])
115       LOG2F_LIBM=
116       dnl Append $ISNANF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
117       case " $LOG2F_LIBM " in
118         *" $ISNANF_LIBM "*) ;;
119         *) LOG2F_LIBM="$LOG2F_LIBM $ISNANF_LIBM" ;;
120       esac
121       dnl Append $FREXPF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
122       case " $LOG2F_LIBM " in
123         *" $FREXPF_LIBM "*) ;;
124         *) LOG2F_LIBM="$LOG2F_LIBM $FREXPF_LIBM" ;;
125       esac
126       dnl Append $LOGF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
127       case " $LOG2F_LIBM " in
128         *" $LOGF_LIBM "*) ;;
129         *) LOG2F_LIBM="$LOG2F_LIBM $LOGF_LIBM" ;;
130       esac
131     fi
132   fi
135 dnl Test whether log2() works.
136 dnl On OSF/1 5.1, log2f(-0.0f) is NaN.
137 dnl On Cygwin 1.7.9, log2f(2^13) is not exactly 13.
138 AC_DEFUN([gl_FUNC_LOG2F_WORKS],
140   AC_REQUIRE([AC_PROG_CC])
141   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
142   AC_CACHE_CHECK([whether log2f works], [gl_cv_func_log2f_works],
143     [
144       AC_RUN_IFELSE(
145         [AC_LANG_SOURCE([[
146 #include <math.h>
147 #ifndef log2f /* for Cygwin 1.7.x */
148 extern
149 #ifdef __cplusplus
151 #endif
152 float log2f (float);
153 #endif
154 volatile float x;
155 volatile float y;
156 int main ()
158   int result = 0;
159   /* This test fails on OSF/1 5.1.  */
160   x = -0.0f;
161   y = log2f (x);
162   if (!(y + y == y))
163     result |= 1;
164   /* This test fails on Cygwin 1.7.9.  */
165   x = 8192.0f;
166   y = log2f (x);
167   if (!(y == 13.0f))
168     result |= 2;
169   return result;
171 ]])],
172         [gl_cv_func_log2f_works=yes],
173         [gl_cv_func_log2f_works=no],
174         [case "$host_os" in
175            cygwin* | osf*) gl_cv_func_log2f_works="guessing no" ;;
176                            # Guess yes on native Windows.
177            mingw*)         gl_cv_func_log2f_works="guessing yes" ;;
178            *)              gl_cv_func_log2f_works="guessing yes" ;;
179          esac
180         ])
181     ])