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_ILOGB],
9 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 dnl Determine ILOGB_LIBM.
12 gl_MATHFUNC([ilogb], [int], [(double)])
13 if test $gl_cv_func_ilogb_no_libm = yes \
14 || test $gl_cv_func_ilogb_in_libm = yes; then
16 LIBS="$LIBS $ILOGB_LIBM"
19 case "$gl_cv_func_ilogb_works" in
26 if test $HAVE_ILOGB = 0 || test $REPLACE_ILOGB = 1; then
27 dnl Find libraries needed to link lib/ilogb.c.
28 AC_REQUIRE([gl_FUNC_FREXP])
29 AC_REQUIRE([gl_FUNC_ISNAND])
31 dnl Append $FREXP_LIBM to ILOGB_LIBM, avoiding gratuitous duplicates.
32 case " $ILOGB_LIBM " in
34 *) ILOGB_LIBM="$ILOGB_LIBM $FREXP_LIBM" ;;
36 dnl Append $ISNAND_LIBM to ILOGB_LIBM, avoiding gratuitous duplicates.
37 case " $ILOGB_LIBM " in
38 *" $ISNAND_LIBM "*) ;;
39 *) ILOGB_LIBM="$ILOGB_LIBM $ISNAND_LIBM" ;;
42 AC_SUBST([ILOGB_LIBM])
45 dnl Test whether ilogb() works.
46 dnl On OpenBSD 6.7, AIX 5.1, ilogb(0.0) is wrong.
47 dnl On AIX 7.1 in 64-bit mode, ilogb(2^(DBL_MIN_EXP-1)) is wrong.
48 dnl On NetBSD 7.1, OpenBSD 6.7, ilogb(Infinity) is wrong.
49 dnl On NetBSD 7.1, OpenBSD 6.7, ilogb(NaN) is wrong.
50 AC_DEFUN([gl_FUNC_ILOGB_WORKS],
52 AC_REQUIRE([AC_PROG_CC])
53 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
54 AC_CACHE_CHECK([whether ilogb works], [gl_cv_func_ilogb_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 ilogb() does */
73 # define FP_ILOGB0 INT_MIN
74 # define FP_ILOGBNAN INT_MIN
76 /* AIX 5.1: match what ilogb() does in AIX >= 5.2 */
77 # define FP_ILOGB0 INT_MIN
78 # define FP_ILOGBNAN INT_MAX
80 /* Solaris 9: match what ilogb() does */
81 # define FP_ILOGB0 (- INT_MAX)
82 # define FP_ILOGBNAN INT_MAX
87 static int dummy (double x) { return 0; }
88 int main (int argc, char *argv[])
90 int (* volatile my_ilogb) (double) = argc ? ilogb : dummy;
92 /* This test fails on OpenBSD 6.7, AIX 5.1. */
95 if (my_ilogb (x) != FP_ILOGB0)
98 /* This test fails on AIX 7.1 in 64-bit mode. */
102 for (i = DBL_MIN_EXP - 1; i < 0; i++)
104 if (x > 0.0 && my_ilogb (x) != DBL_MIN_EXP - 2)
107 /* This test fails on NetBSD 7.1, OpenBSD 6.7. */
110 if (my_ilogb (x) != INT_MAX)
113 /* This test fails on NetBSD 7.1, OpenBSD 6.7. */
116 if (my_ilogb (x) != FP_ILOGBNAN)
122 [gl_cv_func_ilogb_works=yes],
123 [gl_cv_func_ilogb_works=no],
125 aix* | openbsd* | netbsd* | solaris*)
126 gl_cv_func_ilogb_works="guessing no" ;;
127 # Guess yes on native Windows.
128 mingw*) gl_cv_func_ilogb_works="guessing yes" ;;
129 *) gl_cv_func_ilogb_works="guessing yes" ;;