2 dnl Copyright (C) 2010-2013 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 11 2011-11. */
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 # If we don't know, assume the worst.
85 *) gl_cv_func_log2_ieee="guessing no" ;;
90 case "$gl_cv_func_log2_ieee" in
100 if test $HAVE_LOG2 = 0 || test $REPLACE_LOG2 = 1; then
101 dnl Find libraries needed to link lib/log2.c.
102 AC_REQUIRE([gl_FUNC_ISNAND])
103 AC_REQUIRE([gl_FUNC_FREXP])
104 AC_REQUIRE([gl_FUNC_LOG])
106 dnl Append $ISNAND_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
107 case " $LOG2_LIBM " in
108 *" $ISNAND_LIBM "*) ;;
109 *) LOG2_LIBM="$LOG2_LIBM $ISNAND_LIBM" ;;
111 dnl Append $FREXP_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
112 case " $LOG2_LIBM " in
113 *" $FREXP_LIBM "*) ;;
114 *) LOG2_LIBM="$LOG2_LIBM $FREXP_LIBM" ;;
116 dnl Append $LOG_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
117 case " $LOG2_LIBM " in
119 *) LOG2_LIBM="$LOG2_LIBM $LOG_LIBM" ;;
124 dnl Test whether log2() works.
125 dnl On OSF/1 5.1, log2(-0.0) is NaN.
126 dnl On Cygwin 1.7.9, log2(2^29) is not exactly 29.
127 AC_DEFUN([gl_FUNC_LOG2_WORKS],
129 AC_REQUIRE([AC_PROG_CC])
130 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
131 AC_CACHE_CHECK([whether log2 works], [gl_cv_func_log2_works],
136 #ifndef log2 /* for Cygwin 1.7.x */
141 double log2 (double);
148 /* This test fails on OSF/1 5.1. */
153 /* This test fails on Cygwin 1.7.9. */
161 [gl_cv_func_log2_works=yes],
162 [gl_cv_func_log2_works=no],
164 cygwin* | osf*) gl_cv_func_log2_works="guessing no";;
165 *) gl_cv_func_log2_works="guessing yes";;