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
20 LIBS="$LIBS $ILOGBF_LIBM"
23 case "$gl_cv_func_ilogbf_works" in
25 *) REPLACE_ILOGBF=1 ;;
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])
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" ;;
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" ;;
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],
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 */
68 # define FP_ILOGB0 (- 2147483647 - 1) /* INT_MIN */
69 # define FP_ILOGBNAN (- 2147483647 - 1) /* INT_MIN */
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
77 /* AIX 5.1: match what ilogbf() does in AIX >= 5.2 */
78 # define FP_ILOGB0 INT_MIN
79 # define FP_ILOGBNAN INT_MAX
81 /* Solaris 9: match what ilogbf() does */
82 # define FP_ILOGB0 (- INT_MAX)
83 # define FP_ILOGBNAN INT_MAX
88 static int dummy (float x) { return 0; }
89 int main (int argc, char *argv[])
91 int (* volatile my_ilogbf) (float) = argc ? ilogbf : dummy;
93 /* This test fails on OpenBSD 6.7. */
96 if (my_ilogbf (x) != FP_ILOGB0)
99 /* This test fails on NetBSD 7.1, OpenBSD 6.7. */
102 if (my_ilogbf (x) != INT_MAX)
108 [gl_cv_func_ilogbf_works=yes],
109 [gl_cv_func_ilogbf_works=no],
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" ;;