2 dnl Copyright (C) 2010-2017 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 (*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*) gl_cv_func_log2_ieee="guessing yes" ;;
84 # Guess yes on native Windows.
85 mingw*) gl_cv_func_log2_ieee="guessing yes" ;;
86 # If we don't know, assume the worst.
87 *) gl_cv_func_log2_ieee="guessing no" ;;
92 case "$gl_cv_func_log2_ieee" in
102 if test $HAVE_LOG2 = 0 || test $REPLACE_LOG2 = 1; then
103 dnl Find libraries needed to link lib/log2.c.
104 AC_REQUIRE([gl_FUNC_ISNAND])
105 AC_REQUIRE([gl_FUNC_FREXP])
106 AC_REQUIRE([gl_FUNC_LOG])
108 dnl Append $ISNAND_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
109 case " $LOG2_LIBM " in
110 *" $ISNAND_LIBM "*) ;;
111 *) LOG2_LIBM="$LOG2_LIBM $ISNAND_LIBM" ;;
113 dnl Append $FREXP_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
114 case " $LOG2_LIBM " in
115 *" $FREXP_LIBM "*) ;;
116 *) LOG2_LIBM="$LOG2_LIBM $FREXP_LIBM" ;;
118 dnl Append $LOG_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
119 case " $LOG2_LIBM " in
121 *) LOG2_LIBM="$LOG2_LIBM $LOG_LIBM" ;;
126 dnl Test whether log2() works.
127 dnl On OSF/1 5.1, log2(-0.0) is NaN.
128 dnl On Cygwin 1.7.9, log2(2^29) is not exactly 29.
129 AC_DEFUN([gl_FUNC_LOG2_WORKS],
131 AC_REQUIRE([AC_PROG_CC])
132 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
133 AC_CACHE_CHECK([whether log2 works], [gl_cv_func_log2_works],
138 #ifndef log2 /* for Cygwin 1.7.x */
143 double log2 (double);
150 /* This test fails on OSF/1 5.1. */
155 /* This test fails on Cygwin 1.7.9. */
163 [gl_cv_func_log2_works=yes],
164 [gl_cv_func_log2_works=no],
166 cygwin* | osf*) gl_cv_func_log2_works="guessing no" ;;
167 # Guess yes on native Windows.
168 mingw*) gl_cv_func_log2_works="guessing yes" ;;
169 *) gl_cv_func_log2_works="guessing yes" ;;