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_LOG2],
10 m4_divert_text([DEFAULTS], [gl_log2_required=plain])
11 AC_REQUIRE([gl_MATH_H_DEFAULTS])
13 dnl Persuade glibc <math.h> to declare log2().
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16 dnl Determine LOG2_LIBM.
17 gl_COMMON_DOUBLE_MATHFUNC([log2])
19 dnl Test whether log2() exists.
21 LIBS="$LIBS $LOG2_LIBM"
22 gl_CHECK_FUNCS_ANDROID([log2], [[#include <math.h>]])
24 if test $ac_cv_func_log2 = yes; then
26 dnl Also check whether it's declared.
27 dnl IRIX 6.5 has log2() in libm but doesn't declare it in <math.h>.
28 AC_CHECK_DECL([log2], , [HAVE_DECL_LOG2=0], [[#include <math.h>]])
31 LIBS="$LIBS $LOG2_LIBM"
34 case "$gl_cv_func_log2_works" in
39 m4_ifdef([gl_FUNC_LOG2_IEEE], [
40 if test $gl_log2_required = ieee && test $REPLACE_LOG2 = 0; then
41 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
42 AC_CACHE_CHECK([whether log2 works according to ISO C 99 with IEC 60559],
43 [gl_cv_func_log2_ieee],
46 LIBS="$LIBS $LOG2_LIBM"
49 #ifndef __NO_MATH_INLINES
50 # define __NO_MATH_INLINES 1 /* for glibc */
53 #ifndef log2 /* for Cygwin 1.7.x */
60 /* Compare two numbers with ==.
61 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
64 numeric_equal (double x, double y)
68 static double dummy (double x) { return 0; }
69 int main (int argc, char *argv[])
71 double (* volatile my_log2) (double) = argc ? log2 : dummy;
72 /* Test log2(negative).
73 This test fails on NetBSD 5.1 and Solaris 10/x86_64. */
74 double y = my_log2 (-1.0);
75 if (numeric_equal (y, y))
80 [gl_cv_func_log2_ieee=yes],
81 [gl_cv_func_log2_ieee=no],
83 # Guess yes on glibc systems.
84 *-gnu* | gnu*) gl_cv_func_log2_ieee="guessing yes" ;;
85 # Guess yes on musl systems.
86 *-musl* | midipix*) gl_cv_func_log2_ieee="guessing yes" ;;
87 # Guess yes on native Windows.
88 mingw* | windows*) gl_cv_func_log2_ieee="guessing yes" ;;
89 # If we don't know, obey --enable-cross-guesses.
90 *) gl_cv_func_log2_ieee="$gl_cross_guess_normal" ;;
95 case "$gl_cv_func_log2_ieee" in
104 case "$gl_cv_onwards_func_log2" in
105 future*) REPLACE_LOG2=1 ;;
108 if test $HAVE_LOG2 = 0 || test $REPLACE_LOG2 = 1; then
109 dnl Find libraries needed to link lib/log2.c.
110 AC_REQUIRE([gl_FUNC_ISNAND])
111 AC_REQUIRE([gl_FUNC_FREXP])
112 AC_REQUIRE([gl_FUNC_LOG])
114 dnl Append $ISNAND_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
115 case " $LOG2_LIBM " in
116 *" $ISNAND_LIBM "*) ;;
117 *) LOG2_LIBM="$LOG2_LIBM $ISNAND_LIBM" ;;
119 dnl Append $FREXP_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
120 case " $LOG2_LIBM " in
121 *" $FREXP_LIBM "*) ;;
122 *) LOG2_LIBM="$LOG2_LIBM $FREXP_LIBM" ;;
124 dnl Append $LOG_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
125 case " $LOG2_LIBM " in
127 *) LOG2_LIBM="$LOG2_LIBM $LOG_LIBM" ;;
132 dnl Test whether log2() works.
133 dnl On OSF/1 5.1, log2(-0.0) is NaN.
134 dnl On Cygwin 1.7.9, log2(2^29) is not exactly 29.
135 AC_DEFUN([gl_FUNC_LOG2_WORKS],
137 AC_REQUIRE([AC_PROG_CC])
138 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
139 AC_CACHE_CHECK([whether log2 works], [gl_cv_func_log2_works],
144 #ifndef log2 /* for Cygwin 1.7.x */
149 double log2 (double);
156 /* This test fails on OSF/1 5.1. */
161 /* This test fails on Cygwin 1.7.9. */
169 [gl_cv_func_log2_works=yes],
170 [gl_cv_func_log2_works=no],
172 cygwin* | osf*) gl_cv_func_log2_works="guessing no" ;;
173 # Guess yes on native Windows.
174 mingw* | windows*) gl_cv_func_log2_works="guessing yes" ;;
175 *) gl_cv_func_log2_works="guessing yes" ;;