immutable: Add tests.
[gnulib.git] / m4 / logbl.m4
blob0467a2b72da80cd1cf63d8988a994232391679bc
1 # logbl.m4 serial 5
2 dnl Copyright (C) 2012-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_LOGBL],
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
11   AC_REQUIRE([gl_FUNC_LOGB])
13   dnl Persuade glibc <math.h> to declare logbl().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16   dnl Test whether logbl() exists and determine LOGBL_LIBM. We cannot assume
17   dnl that logbl(), if it exists, is defined in the same library as logb().
18   dnl This is not the case on AIX >= 5.2, Solaris >= 10.
19   gl_MATHFUNC([logbl], [long double], [(long double)])
20   if test $gl_cv_func_logbl_no_libm = yes \
21      || test $gl_cv_func_logbl_in_libm = yes; then
22     save_LIBS="$LIBS"
23     LIBS="$LIBS $LOGBL_LIBM"
24     gl_FUNC_LOGBL_WORKS
25     LIBS="$save_LIBS"
26     case "$gl_cv_func_logbl_works" in
27       *yes) ;;
28       *) REPLACE_LOGBL=1 ;;
29     esac
30   else
31     HAVE_LOGBL=0
32   fi
33   if test $HAVE_LOGBL = 0 || test $REPLACE_LOGBL = 1; then
34     dnl Find libraries needed to link lib/logbl.c.
35     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
36       LOGBL_LIBM="$LOGB_LIBM"
37     else
38       AC_REQUIRE([gl_FUNC_FREXPL])
39       AC_REQUIRE([gl_FUNC_ISNANL])
40       LOGBL_LIBM=
41       dnl Append $FREXPL_LIBM to LOGBL_LIBM, avoiding gratuitous duplicates.
42       case " $LOGBL_LIBM " in
43         *" $FREXPL_LIBM "*) ;;
44         *) LOGBL_LIBM="$LOGBL_LIBM $FREXPL_LIBM" ;;
45       esac
46       dnl Append $ISNANL_LIBM to LOGBL_LIBM, avoiding gratuitous duplicates.
47       case " $LOGBL_LIBM " in
48         *" $ISNANL_LIBM "*) ;;
49         *) LOGBL_LIBM="$LOGBL_LIBM $ISNANL_LIBM" ;;
50       esac
51     fi
52   fi
53   AC_SUBST([LOGBL_LIBM])
56 dnl Test whether logbl() works.
57 dnl On glibc 2.11/powerpc, glibc 2.7/sparc, glibc 2.7/hppa, Solaris 10/SPARC,
58 dnl Solaris 11.4/x86_64, the return value for subnormal (denormalized) arguments
59 dnl is too large.
60 dnl On glibc 2.23/powerpc64le, the return value for negative subnormal arguments
61 dnl is too large.
62 AC_DEFUN([gl_FUNC_LOGBL_WORKS],
64   AC_REQUIRE([AC_PROG_CC])
65   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
66   AC_CACHE_CHECK([whether logbl works], [gl_cv_func_logbl_works],
67     [
68       AC_RUN_IFELSE(
69         [AC_LANG_SOURCE([[
70 #include <float.h>
71 #include <math.h>
72 /* Override the values of <float.h>, like done in float.in.h.  */
73 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
74 # undef LDBL_MIN_EXP
75 # define LDBL_MIN_EXP    (-16381)
76 #endif
77 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
78 # undef LDBL_MIN_EXP
79 # define LDBL_MIN_EXP    (-16381)
80 #endif
81 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
82 # undef LDBL_MIN_EXP
83 # define LDBL_MIN_EXP DBL_MIN_EXP
84 #endif
85 #if defined __sgi && (LDBL_MANT_DIG >= 106)
86 # if defined __GNUC__
87 #  undef LDBL_MIN_EXP
88 #  define LDBL_MIN_EXP DBL_MIN_EXP
89 # endif
90 #endif
91 volatile long double x;
92 int main ()
94   int i;
95   for (i = 1, x = 1.0L; i >= LDBL_MIN_EXP - 54; i--, x *= 0.5L)
96     /* Either x = 2^(i-1) or x = 0.0.  */
97     if ((i == LDBL_MIN_EXP - 1 || i == LDBL_MIN_EXP - 54)
98         && (x > 0.0L && !(logbl (x) == (long double)(i - 1))))
99       return 1;
100   for (i = 1, x = -1.0L; i >= LDBL_MIN_EXP - 54; i--, x *= 0.5L)
101     /* Either x = -2^(i-1) or x = 0.0.  */
102     if ((i == LDBL_MIN_EXP - 1 || i == LDBL_MIN_EXP - 54)
103         && (x < 0.0L && !(logbl (x) == (long double)(i - 1))))
104       return 1;
105   return 0;
107 ]])],
108         [gl_cv_func_logbl_works=yes],
109         [gl_cv_func_logbl_works=no],
110         [case "$host_os" in
111            *gnu* | solaris*) gl_cv_func_logbl_works="guessing no" ;;
112                              # Guess yes on native Windows.
113            mingw*)           gl_cv_func_logbl_works="guessing yes" ;;
114            *)                gl_cv_func_logbl_works="guessing yes" ;;
115          esac
116         ])
117     ])