2 dnl Copyright (C) 2010-2021 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_LOGB],
9 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 dnl Persuade glibc <math.h> to declare logb().
12 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14 dnl Test whether logb() is declared.
15 AC_CHECK_DECLS([logb], , , [[#include <math.h>]])
16 if test "$ac_cv_have_decl_logb" != yes; then
19 dnl Test whether logb() can be used without libm.
23 [[#ifndef __NO_MATH_INLINES
24 # define __NO_MATH_INLINES 1 /* for glibc */
31 double logb (double x);
35 if test "$LOGB_LIBM" = "?"; then
40 [[#ifndef __NO_MATH_INLINES
41 # define __NO_MATH_INLINES 1 /* for glibc */
48 double logb (double x);
54 if test "$LOGB_LIBM" != "?"; then
57 LIBS="$LIBS $LOGB_LIBM"
60 case "$gl_cv_func_logb_works" in
67 if test $HAVE_LOGB = 0 || test $REPLACE_LOGB = 1; then
68 dnl Find libraries needed to link lib/logb.c.
69 AC_REQUIRE([gl_FUNC_FREXP])
70 AC_REQUIRE([gl_FUNC_ISNAND])
72 dnl Append $FREXP_LIBM to LOGB_LIBM, avoiding gratuitous duplicates.
73 case " $LOGB_LIBM " in
75 *) LOGB_LIBM="$LOGB_LIBM $FREXP_LIBM" ;;
77 dnl Append $ISNAND_LIBM to LOGB_LIBM, avoiding gratuitous duplicates.
78 case " $LOGB_LIBM " in
79 *" $ISNAND_LIBM "*) ;;
80 *) LOGB_LIBM="$LOGB_LIBM $ISNAND_LIBM" ;;
86 dnl Test whether logb() works.
87 dnl On glibc 2.11/ppc, glibc 2.7/sparc, glibc 2.7/hppa, Solaris 10/SPARC,
88 dnl Solaris 11.4/x86_64, Cygwin 1.5.x, the return value for subnormal
89 dnl (denormalized) arguments is too large.
90 dnl On glibc 2.17/ppc likewise but only for negative subnormal (denormalized)
92 AC_DEFUN([gl_FUNC_LOGB_WORKS],
94 AC_REQUIRE([AC_PROG_CC])
95 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
96 AC_CACHE_CHECK([whether logb works], [gl_cv_func_logb_works],
106 double logb (double);
111 /* This test fails on glibc 2.11/ppc, glibc 2.7/sparc, glibc 2.7/hppa,
112 Solaris 10/SPARC, Solaris 11.4/x86_64, Cygwin 1.5.x. */
115 for (i = 1, x = 1.0; i >= DBL_MIN_EXP; i--, x *= 0.5)
117 /* Here i = DBL_MIN_EXP - 1. Either x = 2^(i-1) is subnormal or x = 0.0. */
118 if (x > 0.0 && !(logb (x) == (double)(i - 1)))
121 /* This test fails on glibc 2.17/ppc. */
124 for (i = 1, x = -1.0; i >= DBL_MIN_EXP; i--, x *= 0.5)
126 /* Here i = DBL_MIN_EXP - 1. Either x = -2^(i-1) is subnormal or x = -0.0. */
127 if (x < 0.0 && !(logb (x) == (double)(i - 1)))
133 [gl_cv_func_logb_works=yes],
134 [gl_cv_func_logb_works=no],
136 *gnu* | solaris* | cygwin*) gl_cv_func_logb_works="guessing no" ;;
137 mingw*) # Guess yes on MSVC, no on mingw.
138 AC_EGREP_CPP([Known], [
143 [gl_cv_func_logb_works="guessing yes"],
144 [gl_cv_func_logb_works="guessing no"])
146 *) gl_cv_func_logb_works="guessing yes" ;;