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_LOG2F],
9 m4_divert_text([DEFAULTS], [gl_log2f_required=plain])
10 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 AC_REQUIRE([gl_FUNC_LOG2])
13 dnl Persuade glibc <math.h> to declare log2f().
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16 dnl Determine LOG2F_LIBM.
17 gl_COMMON_DOUBLE_MATHFUNC([log2f])
19 dnl Test whether log2f() exists.
21 LIBS="$LIBS $LOG2F_LIBM"
22 AC_CHECK_FUNCS([log2f])
24 if test $ac_cv_func_log2f = yes; then
26 dnl Also check whether it's declared.
27 dnl IRIX 6.5 has log2f() in libm but doesn't declare it in <math.h>.
28 AC_CHECK_DECL([log2f], , [HAVE_DECL_LOG2F=0], [[#include <math.h>]])
31 LIBS="$LIBS $LOG2F_LIBM"
34 case "$gl_cv_func_log2f_works" in
39 m4_ifdef([gl_FUNC_LOG2F_IEEE], [
40 if test $gl_log2f_required = ieee && test $REPLACE_LOG2F = 0; then
41 AC_CACHE_CHECK([whether log2f works according to ISO C 99 with IEC 60559],
42 [gl_cv_func_log2f_ieee],
45 LIBS="$LIBS $LOG2F_LIBM"
48 #ifndef __NO_MATH_INLINES
49 # define __NO_MATH_INLINES 1 /* for glibc */
52 #ifndef log2f /* 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 (float x, float y)
67 static float dummy (float x) { return 0; }
68 int main (int argc, char *argv[])
70 float (*my_log2f) (float) = argc ? log2f : dummy;
71 /* Test log2f(negative).
72 This test fails on NetBSD 5.1 and Solaris 11 2011-11. */
73 float y = my_log2f (-1.0f);
74 if (numeric_equal (y, y))
79 [gl_cv_func_log2f_ieee=yes],
80 [gl_cv_func_log2f_ieee=no],
81 [gl_cv_func_log2f_ieee="guessing no"])
84 case "$gl_cv_func_log2f_ieee" in
94 if test $HAVE_LOG2F = 0 || test $REPLACE_LOG2F = 1; then
95 dnl Find libraries needed to link lib/log2f.c.
96 if test $ac_cv_func_log2 = yes; then
97 AC_DEFINE([HAVE_LOG2], [1],
98 [Define to 1 if the log2() function is available in libc or libm.])
99 LOG2F_LIBM="$LOG2_LIBM"
101 AC_REQUIRE([gl_FUNC_ISNANF])
102 AC_REQUIRE([gl_FUNC_FREXPF])
103 AC_REQUIRE([gl_FUNC_LOGF])
105 dnl Append $ISNANF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
106 case " $LOG2F_LIBM " in
107 *" $ISNANF_LIBM "*) ;;
108 *) LOG2F_LIBM="$LOG2F_LIBM $ISNANF_LIBM" ;;
110 dnl Append $FREXPF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
111 case " $LOG2F_LIBM " in
112 *" $FREXPF_LIBM "*) ;;
113 *) LOG2F_LIBM="$LOG2F_LIBM $FREXPF_LIBM" ;;
115 dnl Append $LOGF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
116 case " $LOG2F_LIBM " in
118 *) LOG2F_LIBM="$LOG2F_LIBM $LOGF_LIBM" ;;
124 dnl Test whether log2() works.
125 dnl On OSF/1 5.1, log2f(-0.0f) is NaN.
126 dnl On Cygwin 1.7.9, log2f(2^13) is not exactly 13.
127 AC_DEFUN([gl_FUNC_LOG2F_WORKS],
129 AC_REQUIRE([AC_PROG_CC])
130 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
131 AC_CACHE_CHECK([whether log2f works], [gl_cv_func_log2f_works],
136 #ifndef log2f /* for Cygwin 1.7.x */
148 /* This test fails on OSF/1 5.1. */
153 /* This test fails on Cygwin 1.7.9. */
161 [gl_cv_func_log2f_works=yes],
162 [gl_cv_func_log2f_works=no],
164 cygwin* | osf*) gl_cv_func_log2f_works="guessing no";;
165 *) gl_cv_func_log2f_works="guessing yes";;