mcel: port to uClibc-ng
[gnulib.git] / m4 / ilogbf.m4
blobc996ac2a7703dd25fd87bb45fa60125ec473ef66
1 # ilogbf.m4
2 # serial 8
3 dnl Copyright (C) 2010-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_ILOGBF],
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
12   dnl Persuade glibc <math.h> to declare ilogbf().
13   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15   dnl Determine ILOGBF_LIBM.
16   gl_MATHFUNC([ilogbf], [int], [(float)])
17   if test $gl_cv_func_ilogbf_no_libm = yes \
18      || test $gl_cv_func_ilogbf_in_libm = yes; then
19     saved_LIBS="$LIBS"
20     LIBS="$LIBS $ILOGBF_LIBM"
21     gl_FUNC_ILOGBF_WORKS
22     LIBS="$saved_LIBS"
23     case "$gl_cv_func_ilogbf_works" in
24       *yes) ;;
25       *) REPLACE_ILOGBF=1 ;;
26     esac
27   else
28     HAVE_ILOGBF=0
29   fi
30   if test $HAVE_ILOGBF = 0 || test $REPLACE_ILOGBF = 1; then
31     dnl Find libraries needed to link lib/ilogbf.c.
32     AC_REQUIRE([gl_FUNC_FREXPF])
33     AC_REQUIRE([gl_FUNC_ISNANF])
34     ILOGBF_LIBM=
35     dnl Append $FREXPF_LIBM to ILOGBF_LIBM, avoiding gratuitous duplicates.
36     case " $ILOGBF_LIBM " in
37       *" $FREXPF_LIBM "*) ;;
38       *) ILOGBF_LIBM="$ILOGBF_LIBM $FREXPF_LIBM" ;;
39     esac
40     dnl Append $ISNANF_LIBM to ILOGBF_LIBM, avoiding gratuitous duplicates.
41     case " $ILOGBF_LIBM " in
42       *" $ISNANF_LIBM "*) ;;
43       *) ILOGBF_LIBM="$ILOGBF_LIBM $ISNANF_LIBM" ;;
44     esac
45   fi
46   AC_SUBST([ILOGBF_LIBM])
49 dnl Test whether ilogbf() works.
50 dnl On OpenBSD 6.7, ilogbf(0.0) is wrong.
51 dnl On NetBSD 7.1, OpenBSD 6.7, ilogbf(Infinity) is wrong.
52 AC_DEFUN([gl_FUNC_ILOGBF_WORKS],
54   AC_REQUIRE([AC_PROG_CC])
55   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
56   AC_CACHE_CHECK([whether ilogbf works], [gl_cv_func_ilogbf_works],
57     [
58       AC_RUN_IFELSE(
59         [AC_LANG_SOURCE([[
60 #include <limits.h>
61 #include <math.h>
62 /* Provide FP_ILOGB0, FP_ILOGBNAN, like in math.in.h.  */
63 #if defined FP_ILOGB0 && defined FP_ILOGBNAN
64 # if defined __HAIKU__
65   /* Haiku: match what ilogb() does */
66 #  undef FP_ILOGB0
67 #  undef FP_ILOGBNAN
68 #  define FP_ILOGB0   (- 2147483647 - 1) /* INT_MIN */
69 #  define FP_ILOGBNAN (- 2147483647 - 1) /* INT_MIN */
70 # endif
71 #else
72 # if defined __NetBSD__ || defined __sgi
73   /* NetBSD, IRIX 6.5: match what ilogbf() does */
74 #  define FP_ILOGB0   INT_MIN
75 #  define FP_ILOGBNAN INT_MIN
76 # elif defined _AIX
77   /* AIX 5.1: match what ilogbf() does in AIX >= 5.2 */
78 #  define FP_ILOGB0   INT_MIN
79 #  define FP_ILOGBNAN INT_MAX
80 # elif defined __sun
81   /* Solaris 9: match what ilogbf() does */
82 #  define FP_ILOGB0   (- INT_MAX)
83 #  define FP_ILOGBNAN INT_MAX
84 # endif
85 #endif
86 volatile float x;
87 static float zero;
88 static int dummy (float x) { return 0; }
89 int main (int argc, char *argv[])
91   int (* volatile my_ilogbf) (float) = argc ? ilogbf : dummy;
92   int result = 0;
93   /* This test fails on OpenBSD 6.7.  */
94   {
95     x = 0.0f;
96     if (my_ilogbf (x) != FP_ILOGB0)
97       result |= 1;
98   }
99   /* This test fails on NetBSD 7.1, OpenBSD 6.7.  */
100   {
101     x = 1.0f / zero;
102     if (my_ilogbf (x) != INT_MAX)
103       result |= 2;
104   }
105   return result;
107 ]])],
108         [gl_cv_func_ilogbf_works=yes],
109         [gl_cv_func_ilogbf_works=no],
110         [case "$host_os" in
111            openbsd* | netbsd*)
112                               gl_cv_func_ilogbf_works="guessing no" ;;
113                               # Guess yes on native Windows.
114            mingw* | windows*) gl_cv_func_ilogbf_works="guessing yes" ;;
115            *)                 gl_cv_func_ilogbf_works="guessing yes" ;;
116          esac
117         ])
118     ])