2 dnl Copyright (C) 2010-2012 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_CACHE_CHECK([whether log2 works according to ISO C 99 with IEC 60559],
41 [gl_cv_func_log2_ieee],
44 LIBS="$LIBS $LOG2_LIBM"
47 #ifndef __NO_MATH_INLINES
48 # define __NO_MATH_INLINES 1 /* for glibc */
51 #ifndef log2 /* for Cygwin 1.7.x */
58 /* Compare two numbers with ==.
59 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
62 numeric_equal (double x, double y)
66 static double dummy (double x) { return 0; }
67 int main (int argc, char *argv[])
69 double (*my_log2) (double) = argc ? log2 : dummy;
70 /* Test log2(negative).
71 This test fails on NetBSD 5.1 and Solaris 11 2011-11. */
72 double y = my_log2 (-1.0);
73 if (numeric_equal (y, y))
78 [gl_cv_func_log2_ieee=yes],
79 [gl_cv_func_log2_ieee=no],
80 [gl_cv_func_log2_ieee="guessing no"])
83 case "$gl_cv_func_log2_ieee" in
93 if test $HAVE_LOG2 = 0 || test $REPLACE_LOG2 = 1; then
94 dnl Find libraries needed to link lib/log2.c.
95 AC_REQUIRE([gl_FUNC_ISNAND])
96 AC_REQUIRE([gl_FUNC_FREXP])
97 AC_REQUIRE([gl_FUNC_LOG])
99 dnl Append $ISNAND_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
100 case " $LOG2_LIBM " in
101 *" $ISNAND_LIBM "*) ;;
102 *) LOG2_LIBM="$LOG2_LIBM $ISNAND_LIBM" ;;
104 dnl Append $FREXP_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
105 case " $LOG2_LIBM " in
106 *" $FREXP_LIBM "*) ;;
107 *) LOG2_LIBM="$LOG2_LIBM $FREXP_LIBM" ;;
109 dnl Append $LOG_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
110 case " $LOG2_LIBM " in
112 *) LOG2_LIBM="$LOG2_LIBM $LOG_LIBM" ;;
117 dnl Test whether log2() works.
118 dnl On OSF/1 5.1, log2(-0.0) is NaN.
119 dnl On Cygwin 1.7.9, log2(2^29) is not exactly 29.
120 AC_DEFUN([gl_FUNC_LOG2_WORKS],
122 AC_REQUIRE([AC_PROG_CC])
123 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
124 AC_CACHE_CHECK([whether log2 works], [gl_cv_func_log2_works],
129 #ifndef log2 /* for Cygwin 1.7.x */
134 double log2 (double);
141 /* This test fails on OSF/1 5.1. */
146 /* This test fails on Cygwin 1.7.9. */
154 [gl_cv_func_log2_works=yes],
155 [gl_cv_func_log2_works=no],
157 cygwin* | osf*) gl_cv_func_log2_works="guessing no";;
158 *) gl_cv_func_log2_works="guessing yes";;