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_LOG2],
9 m4_divert_text([DEFAULTS], [gl_log2_required=plain])
10 AC_REQUIRE([gl_MATH_H_DEFAULTS])
12 dnl Persuade glibc <math.h> to declare log2().
13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15 dnl Determine LOG2_LIBM.
16 gl_COMMON_DOUBLE_MATHFUNC([log2])
18 dnl Test whether log2() exists.
20 LIBS="$LIBS $LOG2_LIBM"
21 AC_CHECK_FUNCS([log2])
23 if test $ac_cv_func_log2 = yes; then
25 dnl Also check whether it's declared.
26 dnl IRIX 6.5 has log2() in libm but doesn't declare it in <math.h>.
27 AC_CHECK_DECL([log2], , [HAVE_DECL_LOG2=0], [[#include <math.h>]])
30 LIBS="$LIBS $LOG2_LIBM"
33 case "$gl_cv_func_log2_works" in
38 m4_ifdef([gl_FUNC_LOG2_IEEE], [
39 if test $gl_log2_required = ieee && test $REPLACE_LOG2 = 0; then
40 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
41 AC_CACHE_CHECK([whether log2 works according to ISO C 99 with IEC 60559],
42 [gl_cv_func_log2_ieee],
45 LIBS="$LIBS $LOG2_LIBM"
48 #ifndef __NO_MATH_INLINES
49 # define __NO_MATH_INLINES 1 /* for glibc */
52 #ifndef log2 /* for Cygwin 1.7.x */
59 /* Compare two numbers with ==.
60 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
63 numeric_equal (double x, double y)
67 static double dummy (double x) { return 0; }
68 int main (int argc, char *argv[])
70 double (* volatile my_log2) (double) = argc ? log2 : dummy;
71 /* Test log2(negative).
72 This test fails on NetBSD 5.1 and Solaris 10/x86_64. */
73 double y = my_log2 (-1.0);
74 if (numeric_equal (y, y))
79 [gl_cv_func_log2_ieee=yes],
80 [gl_cv_func_log2_ieee=no],
82 # Guess yes on glibc systems.
83 *-gnu* | gnu*) gl_cv_func_log2_ieee="guessing yes" ;;
84 # Guess yes on musl systems.
85 *-musl*) gl_cv_func_log2_ieee="guessing yes" ;;
86 # Guess yes on native Windows.
87 mingw*) gl_cv_func_log2_ieee="guessing yes" ;;
88 # If we don't know, obey --enable-cross-guesses.
89 *) gl_cv_func_log2_ieee="$gl_cross_guess_normal" ;;
94 case "$gl_cv_func_log2_ieee" in
104 if test $HAVE_LOG2 = 0 || test $REPLACE_LOG2 = 1; then
105 dnl Find libraries needed to link lib/log2.c.
106 AC_REQUIRE([gl_FUNC_ISNAND])
107 AC_REQUIRE([gl_FUNC_FREXP])
108 AC_REQUIRE([gl_FUNC_LOG])
110 dnl Append $ISNAND_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
111 case " $LOG2_LIBM " in
112 *" $ISNAND_LIBM "*) ;;
113 *) LOG2_LIBM="$LOG2_LIBM $ISNAND_LIBM" ;;
115 dnl Append $FREXP_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
116 case " $LOG2_LIBM " in
117 *" $FREXP_LIBM "*) ;;
118 *) LOG2_LIBM="$LOG2_LIBM $FREXP_LIBM" ;;
120 dnl Append $LOG_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
121 case " $LOG2_LIBM " in
123 *) LOG2_LIBM="$LOG2_LIBM $LOG_LIBM" ;;
128 dnl Test whether log2() works.
129 dnl On OSF/1 5.1, log2(-0.0) is NaN.
130 dnl On Cygwin 1.7.9, log2(2^29) is not exactly 29.
131 AC_DEFUN([gl_FUNC_LOG2_WORKS],
133 AC_REQUIRE([AC_PROG_CC])
134 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
135 AC_CACHE_CHECK([whether log2 works], [gl_cv_func_log2_works],
140 #ifndef log2 /* for Cygwin 1.7.x */
145 double log2 (double);
152 /* This test fails on OSF/1 5.1. */
157 /* This test fails on Cygwin 1.7.9. */
165 [gl_cv_func_log2_works=yes],
166 [gl_cv_func_log2_works=no],
168 cygwin* | osf*) gl_cv_func_log2_works="guessing no" ;;
169 # Guess yes on native Windows.
170 mingw*) gl_cv_func_log2_works="guessing yes" ;;
171 *) gl_cv_func_log2_works="guessing yes" ;;