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_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 AC_DEFUN([gl_FUNC_LOGB_WORKS],
92 AC_REQUIRE([AC_PROG_CC])
93 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
94 AC_CACHE_CHECK([whether logb works], [gl_cv_func_logb_works],
104 double logb (double);
109 for (i = 1, x = 1.0; i >= DBL_MIN_EXP; i--, x *= 0.5)
111 /* Here i = DBL_MIN_EXP - 1. Either x = 2^(i-1) is subnormal or x = 0.0. */
112 if (x > 0.0 && !(logb (x) == (double)(i - 1)))
117 [gl_cv_func_logb_works=yes],
118 [gl_cv_func_logb_works=no],
120 *gnu* | solaris* | cygwin*) gl_cv_func_logb_works="guessing no" ;;
121 mingw*) # Guess yes on MSVC, no on mingw.
122 AC_EGREP_CPP([Known], [
127 [gl_cv_func_logb_works="guessing yes"],
128 [gl_cv_func_logb_works="guessing no"])
130 *) gl_cv_func_logb_works="guessing yes" ;;