2 dnl Copyright (C) 2010-2020 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_ILOGBF],
9 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 dnl Persuade glibc <math.h> to declare ilogbf().
12 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14 dnl Determine ILOGBF_LIBM.
15 gl_MATHFUNC([ilogbf], [int], [(float)])
16 if test $gl_cv_func_ilogbf_no_libm = yes \
17 || test $gl_cv_func_ilogbf_in_libm = yes; then
19 LIBS="$LIBS $ILOGBF_LIBM"
22 case "$gl_cv_func_ilogbf_works" in
24 *) REPLACE_ILOGBF=1 ;;
29 if test $HAVE_ILOGBF = 0 || test $REPLACE_ILOGBF = 1; then
30 dnl Find libraries needed to link lib/ilogbf.c.
31 AC_REQUIRE([gl_FUNC_FREXPF])
32 AC_REQUIRE([gl_FUNC_ISNANF])
34 dnl Append $FREXPF_LIBM to ILOGBF_LIBM, avoiding gratuitous duplicates.
35 case " $ILOGBF_LIBM " in
36 *" $FREXPF_LIBM "*) ;;
37 *) ILOGBF_LIBM="$ILOGBF_LIBM $FREXPF_LIBM" ;;
39 dnl Append $ISNANF_LIBM to ILOGBF_LIBM, avoiding gratuitous duplicates.
40 case " $ILOGBF_LIBM " in
41 *" $ISNANF_LIBM "*) ;;
42 *) ILOGBF_LIBM="$ILOGBF_LIBM $ISNANF_LIBM" ;;
45 AC_SUBST([ILOGBF_LIBM])
48 dnl Test whether ilogbf() works.
49 dnl On OpenBSD 6.7, ilogbf(0.0) is wrong.
50 dnl On NetBSD 7.1, OpenBSD 6.7, ilogbf(Infinity) is wrong.
51 AC_DEFUN([gl_FUNC_ILOGBF_WORKS],
53 AC_REQUIRE([AC_PROG_CC])
54 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
55 AC_CACHE_CHECK([whether ilogbf works], [gl_cv_func_ilogbf_works],
61 /* Provide FP_ILOGB0, FP_ILOGBNAN, like in math.in.h. */
62 #if defined FP_ILOGB0 && defined FP_ILOGBNAN
63 # if defined __HAIKU__
64 /* Haiku: match what ilogb() does */
67 # define FP_ILOGB0 (- 2147483647 - 1) /* INT_MIN */
68 # define FP_ILOGBNAN (- 2147483647 - 1) /* INT_MIN */
71 # if defined __NetBSD__ || defined __sgi
72 /* NetBSD, IRIX 6.5: match what ilogbf() does */
73 # define FP_ILOGB0 INT_MIN
74 # define FP_ILOGBNAN INT_MIN
76 /* AIX 5.1: match what ilogbf() does in AIX >= 5.2 */
77 # define FP_ILOGB0 INT_MIN
78 # define FP_ILOGBNAN INT_MAX
80 /* Solaris 9: match what ilogbf() does */
81 # define FP_ILOGB0 (- INT_MAX)
82 # define FP_ILOGBNAN INT_MAX
87 static int dummy (float x) { return 0; }
88 int main (int argc, char *argv[])
90 int (* volatile my_ilogbf) (float) = argc ? ilogbf : dummy;
92 /* This test fails on OpenBSD 6.7. */
95 if (my_ilogbf (x) != FP_ILOGB0)
98 /* This test fails on NetBSD 7.1, OpenBSD 6.7. */
101 if (my_ilogbf (x) != INT_MAX)
107 [gl_cv_func_ilogbf_works=yes],
108 [gl_cv_func_ilogbf_works=no],
111 gl_cv_func_ilogbf_works="guessing no" ;;
112 # Guess yes on native Windows.
113 mingw*) gl_cv_func_ilogbf_works="guessing yes" ;;
114 *) gl_cv_func_ilogbf_works="guessing yes" ;;