2 dnl Copyright (C) 2010-2018 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_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
42 AC_CACHE_CHECK([whether log2f works according to ISO C 99 with IEC 60559],
43 [gl_cv_func_log2f_ieee],
46 LIBS="$LIBS $LOG2F_LIBM"
49 #ifndef __NO_MATH_INLINES
50 # define __NO_MATH_INLINES 1 /* for glibc */
53 #ifndef log2f /* for Cygwin 1.7.x */
60 /* Compare two numbers with ==.
61 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
64 numeric_equal (float x, float y)
68 static float dummy (float x) { return 0; }
69 int main (int argc, char *argv[])
71 float (*my_log2f) (float) = argc ? log2f : dummy;
72 /* Test log2f(negative).
73 This test fails on NetBSD 5.1 and Solaris 10/x86_64. */
74 float y = my_log2f (-1.0f);
75 if (numeric_equal (y, y))
80 [gl_cv_func_log2f_ieee=yes],
81 [gl_cv_func_log2f_ieee=no],
83 # Guess yes on glibc systems.
84 *-gnu* | gnu*) gl_cv_func_log2f_ieee="guessing yes" ;;
85 # Guess yes on native Windows.
86 mingw*) gl_cv_func_log2f_ieee="guessing yes" ;;
87 # If we don't know, assume the worst.
88 *) gl_cv_func_log2f_ieee="guessing no" ;;
93 case "$gl_cv_func_log2f_ieee" in
103 if test $HAVE_LOG2F = 0 || test $REPLACE_LOG2F = 1; then
104 dnl Find libraries needed to link lib/log2f.c.
105 if test $ac_cv_func_log2 = yes; then
106 AC_DEFINE([HAVE_LOG2], [1],
107 [Define to 1 if the log2() function is available in libc or libm.])
108 LOG2F_LIBM="$LOG2_LIBM"
110 AC_REQUIRE([gl_FUNC_ISNANF])
111 AC_REQUIRE([gl_FUNC_FREXPF])
112 AC_REQUIRE([gl_FUNC_LOGF])
114 dnl Append $ISNANF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
115 case " $LOG2F_LIBM " in
116 *" $ISNANF_LIBM "*) ;;
117 *) LOG2F_LIBM="$LOG2F_LIBM $ISNANF_LIBM" ;;
119 dnl Append $FREXPF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
120 case " $LOG2F_LIBM " in
121 *" $FREXPF_LIBM "*) ;;
122 *) LOG2F_LIBM="$LOG2F_LIBM $FREXPF_LIBM" ;;
124 dnl Append $LOGF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
125 case " $LOG2F_LIBM " in
127 *) LOG2F_LIBM="$LOG2F_LIBM $LOGF_LIBM" ;;
133 dnl Test whether log2() works.
134 dnl On OSF/1 5.1, log2f(-0.0f) is NaN.
135 dnl On Cygwin 1.7.9, log2f(2^13) is not exactly 13.
136 AC_DEFUN([gl_FUNC_LOG2F_WORKS],
138 AC_REQUIRE([AC_PROG_CC])
139 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
140 AC_CACHE_CHECK([whether log2f works], [gl_cv_func_log2f_works],
145 #ifndef log2f /* for Cygwin 1.7.x */
157 /* This test fails on OSF/1 5.1. */
162 /* This test fails on Cygwin 1.7.9. */
170 [gl_cv_func_log2f_works=yes],
171 [gl_cv_func_log2f_works=no],
173 cygwin* | osf*) gl_cv_func_log2f_works="guessing no" ;;
174 # Guess yes on native Windows.
175 mingw*) gl_cv_func_log2f_works="guessing yes" ;;
176 *) gl_cv_func_log2f_works="guessing yes" ;;