diffseq: don’t worry about clang
[gnulib.git] / m4 / log2l.m4
blobe107cbf1fa3f10484ee9d8a17232723ecf14635a
1 # log2l.m4
2 # serial 9
3 dnl Copyright (C) 2010-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_LOG2L],
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12   AC_REQUIRE([gl_FUNC_LOG2])
14   dnl Persuade glibc <math.h> to declare log2l().
15   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17   dnl Test whether log2l() exists. Assume that log2l(), if it exists, is
18   dnl defined in the same library as log2().
19   saved_LIBS="$LIBS"
20   LIBS="$LIBS $LOG2_LIBM"
21   gl_CHECK_FUNCS_ANDROID([log2l], [[#include <math.h>]])
22   LIBS="$saved_LIBS"
23   if test $ac_cv_func_log2l = yes; then
24     LOG2L_LIBM="$LOG2_LIBM"
25     HAVE_LOG2L=1
26     dnl Also check whether it's declared.
27     dnl IRIX 6.5 has log2l() in libm but doesn't declare it in <math.h>.
28     AC_CHECK_DECL([log2l], , [HAVE_DECL_LOG2L=0], [[#include <math.h>]])
30     saved_LIBS="$LIBS"
31     LIBS="$LIBS $LOG2L_LIBM"
32     gl_FUNC_LOG2L_WORKS
33     LIBS="$saved_LIBS"
34     case "$gl_cv_func_log2l_works" in
35       *yes) ;;
36       *) REPLACE_LOG2L=1 ;;
37     esac
38   else
39     HAVE_LOG2L=0
40     HAVE_DECL_LOG2L=0
41     case "$gl_cv_onwards_func_log2l" in
42       future*) REPLACE_LOG2L=1 ;;
43     esac
44   fi
45   if test $HAVE_LOG2L = 0 || test $REPLACE_LOG2L = 1; then
46     dnl Find libraries needed to link lib/log2l.c.
47     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
48       LOG2L_LIBM="$LOG2_LIBM"
49     else
50       AC_REQUIRE([gl_FUNC_ISNANL])
51       AC_REQUIRE([gl_FUNC_FREXPL])
52       AC_REQUIRE([gl_FUNC_LOGL])
53       LOG2L_LIBM=
54       dnl Append $ISNANL_LIBM to LOG2L_LIBM, avoiding gratuitous duplicates.
55       case " $LOG2L_LIBM " in
56         *" $ISNANL_LIBM "*) ;;
57         *) LOG2L_LIBM="$LOG2L_LIBM $ISNANL_LIBM" ;;
58       esac
59       dnl Append $FREXPL_LIBM to LOG2L_LIBM, avoiding gratuitous duplicates.
60       case " $LOG2L_LIBM " in
61         *" $FREXPL_LIBM "*) ;;
62         *) LOG2L_LIBM="$LOG2L_LIBM $FREXPL_LIBM" ;;
63       esac
64       dnl Append $LOGL_LIBM to LOG2L_LIBM, avoiding gratuitous duplicates.
65       case " $LOG2L_LIBM " in
66         *" $LOGL_LIBM "*) ;;
67         *) LOG2L_LIBM="$LOG2L_LIBM $LOGL_LIBM" ;;
68       esac
69     fi
70   fi
71   AC_SUBST([LOG2L_LIBM])
74 dnl Test whether log2l() works.
75 dnl On OSF/1 5.1, log2l(-0.0) is NaN.
76 dnl On musl 1.2.2/{arm64,s390x}, the result is accurate to only 16 digits.
77 dnl On musl 1.2.2/{arm64,s390x} and NetBSD 10.0, the result is Infinity for
78 dnl some large finite arguments.
79 AC_DEFUN([gl_FUNC_LOG2L_WORKS],
81   AC_REQUIRE([AC_PROG_CC])
82   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
83   AC_CACHE_CHECK([whether log2l works], [gl_cv_func_log2l_works],
84     [
85       AC_RUN_IFELSE(
86         [AC_LANG_SOURCE([[
87 #ifndef __NO_MATH_INLINES
88 # define __NO_MATH_INLINES 1 /* for glibc */
89 #endif
90 #include <float.h>
91 #include <math.h>
92 /* Override the values of <float.h>, like done in float.in.h.  */
93 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
94 # undef LDBL_MANT_DIG
95 # define LDBL_MANT_DIG   64
96 # undef LDBL_MIN_EXP
97 # define LDBL_MIN_EXP    (-16381)
98 # undef LDBL_MAX_EXP
99 # define LDBL_MAX_EXP    16384
100 #endif
101 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
102 # undef LDBL_MANT_DIG
103 # define LDBL_MANT_DIG   64
104 # undef LDBL_MIN_EXP
105 # define LDBL_MIN_EXP    (-16381)
106 # undef LDBL_MAX_EXP
107 # define LDBL_MAX_EXP    16384
108 #endif
109 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
110 # undef LDBL_MIN_EXP
111 # define LDBL_MIN_EXP DBL_MIN_EXP
112 #endif
113 #if defined __sgi && (LDBL_MANT_DIG >= 106)
114 # undef LDBL_MANT_DIG
115 # define LDBL_MANT_DIG 106
116 # if defined __GNUC__
117 #  undef LDBL_MIN_EXP
118 #  define LDBL_MIN_EXP DBL_MIN_EXP
119 # endif
120 #endif
121 #ifndef log2l /* for AIX */
122 extern
123 #ifdef __cplusplus
125 #endif
126 long double log2l (long double);
127 #endif
128 static long double dummy (long double x) { return 0; }
129 volatile long double gx;
130 volatile long double gy;
131 int main (int argc, char *argv[])
133   long double (* volatile my_log2l) (long double) = argc ? log2l : dummy;
134   int result = 0;
135   /* This test fails on OSF/1 5.1.  */
136   {
137     gx = -0.0L;
138     gy = my_log2l (gx);
139     if (!(gy + gy == gy))
140       result |= 1;
141   }
142   /* This test fails on musl 1.2.2/arm64, musl 1.2.2/s390x.  */
143   {
144     const long double TWO_LDBL_MANT_DIG = /* 2^LDBL_MANT_DIG */
145       (long double) (1U << ((LDBL_MANT_DIG - 1) / 5))
146       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 1) / 5))
147       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 2) / 5))
148       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 3) / 5))
149       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 4) / 5));
150     long double x = 11.358L;
151     long double y = my_log2l (x);
152     long double z = my_log2l (1.0L / x);
153     long double err = (y + z) * TWO_LDBL_MANT_DIG;
154     if (!(err >= -10000.0L && err <= 10000.0L))
155       result |= 2;
156   }
157   /* This test fails on musl 1.2.2/arm64, musl 1.2.2/s390x, NetBSD 10.0.  */
158   if (DBL_MAX_EXP < LDBL_MAX_EXP)
159     {
160       long double x = ldexpl (1.0L, DBL_MAX_EXP); /* finite! */
161       long double y = my_log2l (x);
162       if (y > 0 && y + y == y) /* infinite? */
163         result |= 4;
164     }
165   return result;
167 ]])],
168         [gl_cv_func_log2l_works=yes],
169         [gl_cv_func_log2l_works=no],
170         [case "$host_os" in
171                                # Guess yes on glibc systems.
172            *-gnu* | gnu*)      gl_cv_func_log2l_works="guessing yes" ;;
173                                # Guess no on musl systems.
174            *-musl* | midipix*) gl_cv_func_log2l_works="guessing no" ;;
175                                # Guess no on NetBSD and OSF/1.
176            netbsd* | osf*)     gl_cv_func_log2l_works="guessing no" ;;
177                                # Guess yes on native Windows.
178            mingw* | windows*)  gl_cv_func_log2l_works="guessing yes" ;;
179                                # If we don't know, obey --enable-cross-guesses.
180            *)                  gl_cv_func_log2l_works="$gl_cross_guess_normal" ;;
181          esac
182         ])
183     ])