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 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 dnl Persuade glibc <math.h> to declare log2().
12 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14 dnl Determine LOG2_LIBM.
15 gl_COMMON_DOUBLE_MATHFUNC([log2])
17 dnl Test whether log2() exists.
19 LIBS="$LIBS $LOG2_LIBM"
20 AC_CHECK_FUNCS([log2])
22 if test $ac_cv_func_log2 = yes; then
24 dnl Also check whether it's declared.
25 dnl IRIX 6.5 has log2() in libm but doesn't declare it in <math.h>.
26 AC_CHECK_DECL([log2], , [HAVE_DECL_LOG2=0], [[#include <math.h>]])
29 LIBS="$LIBS $LOG2_LIBM"
32 case "$gl_cv_func_log2_works" in
40 if test $HAVE_LOG2 = 0 || test $REPLACE_LOG2 = 1; then
41 dnl Find libraries needed to link lib/log2.c.
42 AC_REQUIRE([gl_FUNC_ISNAND])
43 AC_REQUIRE([gl_FUNC_FREXP])
44 AC_REQUIRE([gl_FUNC_LOG])
46 dnl Append $ISNAND_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
47 case " $LOG2_LIBM " in
48 *" $ISNAND_LIBM "*) ;;
49 *) LOG2_LIBM="$LOG2_LIBM $ISNAND_LIBM" ;;
51 dnl Append $FREXP_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
52 case " $LOG2_LIBM " in
54 *) LOG2_LIBM="$LOG2_LIBM $FREXP_LIBM" ;;
56 dnl Append $LOG_LIBM to LOG2_LIBM, avoiding gratuitous duplicates.
57 case " $LOG2_LIBM " in
59 *) LOG2_LIBM="$LOG2_LIBM $LOG_LIBM" ;;
64 dnl Test whether log2() works.
65 dnl On OSF/1 5.1, log2(-0.0) is NaN.
66 dnl On Cygwin 1.7.9, log2(2^29) is not exactly 29.
67 AC_DEFUN([gl_FUNC_LOG2_WORKS],
69 AC_REQUIRE([AC_PROG_CC])
70 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
71 AC_CACHE_CHECK([whether log2 works], [gl_cv_func_log2_works],
76 #ifndef log2 /* for Cygwin 1.7.x */
88 /* This test fails on OSF/1 5.1. */
93 /* This test fails on Cygwin 1.7.9. */
101 [gl_cv_func_log2_works=yes],
102 [gl_cv_func_log2_works=no],
104 cygwin* | osf*) gl_cv_func_log2_works="guessing no";;
105 *) gl_cv_func_log2_works="guessing yes";;