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_ILOGB],
10 AC_REQUIRE([gl_MATH_H_DEFAULTS])
12 dnl Determine ILOGB_LIBM.
13 gl_MATHFUNC([ilogb], [int], [(double)])
14 if test $gl_cv_func_ilogb_no_libm = yes \
15 || test $gl_cv_func_ilogb_in_libm = yes; then
17 LIBS="$LIBS $ILOGB_LIBM"
20 case "$gl_cv_func_ilogb_works" in
27 if test $HAVE_ILOGB = 0 || test $REPLACE_ILOGB = 1; then
28 dnl Find libraries needed to link lib/ilogb.c.
29 AC_REQUIRE([gl_FUNC_FREXP])
30 AC_REQUIRE([gl_FUNC_ISNAND])
32 dnl Append $FREXP_LIBM to ILOGB_LIBM, avoiding gratuitous duplicates.
33 case " $ILOGB_LIBM " in
35 *) ILOGB_LIBM="$ILOGB_LIBM $FREXP_LIBM" ;;
37 dnl Append $ISNAND_LIBM to ILOGB_LIBM, avoiding gratuitous duplicates.
38 case " $ILOGB_LIBM " in
39 *" $ISNAND_LIBM "*) ;;
40 *) ILOGB_LIBM="$ILOGB_LIBM $ISNAND_LIBM" ;;
43 AC_SUBST([ILOGB_LIBM])
46 dnl Test whether ilogb() works.
47 dnl On OpenBSD 6.7, AIX 5.1, ilogb(0.0) is wrong.
48 dnl On Mac OS X 10.5 in 64-bit mode and on AIX 7.1 in 64-bit mode,
49 dnl ilogb(2^(DBL_MIN_EXP-1)) is wrong.
50 dnl On NetBSD 7.1, OpenBSD 6.7, ilogb(Infinity) is wrong.
51 dnl On NetBSD 7.1, OpenBSD 6.7, ilogb(NaN) is wrong.
52 AC_DEFUN([gl_FUNC_ILOGB_WORKS],
54 AC_REQUIRE([AC_PROG_CC])
55 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
56 AC_CACHE_CHECK([whether ilogb works], [gl_cv_func_ilogb_works],
63 /* Provide FP_ILOGB0, FP_ILOGBNAN, like in math.in.h. */
64 #if defined FP_ILOGB0 && defined FP_ILOGBNAN
65 # if defined __HAIKU__
66 /* Haiku: match what ilogb() does */
69 # define FP_ILOGB0 (- 2147483647 - 1) /* INT_MIN */
70 # define FP_ILOGBNAN (- 2147483647 - 1) /* INT_MIN */
73 # if defined __NetBSD__ || defined __sgi
74 /* NetBSD, IRIX 6.5: match what ilogb() does */
75 # define FP_ILOGB0 INT_MIN
76 # define FP_ILOGBNAN INT_MIN
78 /* AIX 5.1: match what ilogb() does in AIX >= 5.2 */
79 # define FP_ILOGB0 INT_MIN
80 # define FP_ILOGBNAN INT_MAX
82 /* Solaris 9: match what ilogb() does */
83 # define FP_ILOGB0 (- INT_MAX)
84 # define FP_ILOGBNAN INT_MAX
89 static int dummy (double x) { return 0; }
90 int main (int argc, char *argv[])
92 int (* volatile my_ilogb) (double) = argc ? ilogb : dummy;
94 /* This test fails on OpenBSD 6.7, AIX 5.1. */
97 if (my_ilogb (x) != FP_ILOGB0)
100 /* This test fails on Mac OS X 10.5 in 64-bit mode and on
101 AIX 7.1 in 64-bit mode. */
105 for (i = DBL_MIN_EXP - 1; i < 0; i++)
107 if (x > 0.0 && my_ilogb (x) != DBL_MIN_EXP - 2)
110 /* This test fails on NetBSD 7.1, OpenBSD 6.7. */
113 if (my_ilogb (x) != INT_MAX)
116 /* This test fails on NetBSD 7.1, OpenBSD 6.7. */
119 if (my_ilogb (x) != FP_ILOGBNAN)
125 [gl_cv_func_ilogb_works=yes],
126 [gl_cv_func_ilogb_works=no],
128 aix* | openbsd* | netbsd* | solaris*)
129 gl_cv_func_ilogb_works="guessing no" ;;
130 # Guess yes on native Windows.
132 gl_cv_func_ilogb_works="guessing yes" ;;
133 *) gl_cv_func_ilogb_works="guessing yes" ;;