2 dnl Copyright (C) 2010-2020 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 (* volatile 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 musl systems.
86 *-musl*) gl_cv_func_log2f_ieee="guessing yes" ;;
87 # Guess yes on native Windows.
88 mingw*) gl_cv_func_log2f_ieee="guessing yes" ;;
89 # If we don't know, obey --enable-cross-guesses.
90 *) gl_cv_func_log2f_ieee="$gl_cross_guess_normal" ;;
95 case "$gl_cv_func_log2f_ieee" in
105 if test $HAVE_LOG2F = 0 || test $REPLACE_LOG2F = 1; then
106 dnl Find libraries needed to link lib/log2f.c.
107 if test $ac_cv_func_log2 = yes; then
108 AC_DEFINE([HAVE_LOG2], [1],
109 [Define to 1 if the log2() function is available in libc or libm.])
110 LOG2F_LIBM="$LOG2_LIBM"
112 AC_REQUIRE([gl_FUNC_ISNANF])
113 AC_REQUIRE([gl_FUNC_FREXPF])
114 AC_REQUIRE([gl_FUNC_LOGF])
116 dnl Append $ISNANF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
117 case " $LOG2F_LIBM " in
118 *" $ISNANF_LIBM "*) ;;
119 *) LOG2F_LIBM="$LOG2F_LIBM $ISNANF_LIBM" ;;
121 dnl Append $FREXPF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
122 case " $LOG2F_LIBM " in
123 *" $FREXPF_LIBM "*) ;;
124 *) LOG2F_LIBM="$LOG2F_LIBM $FREXPF_LIBM" ;;
126 dnl Append $LOGF_LIBM to LOG2F_LIBM, avoiding gratuitous duplicates.
127 case " $LOG2F_LIBM " in
129 *) LOG2F_LIBM="$LOG2F_LIBM $LOGF_LIBM" ;;
135 dnl Test whether log2() works.
136 dnl On OSF/1 5.1, log2f(-0.0f) is NaN.
137 dnl On Cygwin 1.7.9, log2f(2^13) is not exactly 13.
138 AC_DEFUN([gl_FUNC_LOG2F_WORKS],
140 AC_REQUIRE([AC_PROG_CC])
141 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
142 AC_CACHE_CHECK([whether log2f works], [gl_cv_func_log2f_works],
147 #ifndef log2f /* for Cygwin 1.7.x */
159 /* This test fails on OSF/1 5.1. */
164 /* This test fails on Cygwin 1.7.9. */
172 [gl_cv_func_log2f_works=yes],
173 [gl_cv_func_log2f_works=no],
175 cygwin* | osf*) gl_cv_func_log2f_works="guessing no" ;;
176 # Guess yes on native Windows.
177 mingw*) gl_cv_func_log2f_works="guessing yes" ;;
178 *) gl_cv_func_log2f_works="guessing yes" ;;