Allow use of --avoid=extensions-aix.
[gnulib.git] / m4 / log1pl.m4
blobc1516f3bba549ee231044866600320086541cbd5
1 # log1pl.m4
2 # serial 13
3 dnl Copyright (C) 2012-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_LOG1PL],
10   m4_divert_text([DEFAULTS], [gl_log1pl_required=plain])
11   AC_REQUIRE([gl_MATH_H_DEFAULTS])
12   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
13   AC_REQUIRE([gl_FUNC_LOG1P])
15   dnl Persuade glibc <math.h> to declare log1pl().
16   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
18   dnl Test whether log1pl() exists. Assume that log1pl(), if it exists, is
19   dnl defined in the same library as log1p().
20   saved_LIBS="$LIBS"
21   LIBS="$LIBS $LOG1P_LIBM"
22   AC_CHECK_FUNCS([log1pl])
23   LIBS="$saved_LIBS"
24   if test $ac_cv_func_log1pl = yes; then
25     LOG1PL_LIBM="$LOG1P_LIBM"
27     saved_LIBS="$LIBS"
28     LIBS="$LIBS $LOG1PL_LIBM"
29     gl_FUNC_LOG1PL_WORKS
30     LIBS="$saved_LIBS"
31     case "$gl_cv_func_log1pl_works" in
32       *yes) ;;
33       *) REPLACE_LOG1PL=1 ;;
34     esac
36     m4_ifdef([gl_FUNC_LOG1PL_IEEE], [
37       if test $gl_log1pl_required = ieee && test $REPLACE_LOG1PL = 0; then
38         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
39         AC_CACHE_CHECK([whether log1pl works according to ISO C 99 with IEC 60559],
40           [gl_cv_func_log1pl_ieee],
41           [
42             saved_LIBS="$LIBS"
43             LIBS="$LIBS $LOG1PL_LIBM"
44             AC_RUN_IFELSE(
45               [AC_LANG_SOURCE([[
46 #ifndef __NO_MATH_INLINES
47 # define __NO_MATH_INLINES 1 /* for glibc */
48 #endif
49 #include <math.h>
50 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
51 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
52 static long double dummy (long double x) { return 0; }
53 int main (int argc, char *argv[])
55   long double (* volatile my_log1pl) (long double) = argc ? log1pl : dummy;
56   /* This test fails on AIX 7.1, IRIX 6.5.  */
57   long double y = my_log1pl (minus_zerol);
58   if (!(y == 0.0L) || (signbitl (minus_zerol) && !signbitl (y)))
59     return 1;
60   return 0;
62               ]])],
63               [gl_cv_func_log1pl_ieee=yes],
64               [gl_cv_func_log1pl_ieee=no],
65               [case "$host_os" in
66                                      # Guess yes on glibc systems.
67                  *-gnu* | gnu*)      gl_cv_func_log1pl_ieee="guessing yes" ;;
68                                      # Guess yes on musl systems.
69                  *-musl* | midipix*) gl_cv_func_log1pl_ieee="guessing yes" ;;
70                                      # Guess yes on native Windows.
71                  mingw* | windows*)  gl_cv_func_log1pl_ieee="guessing yes" ;;
72                                      # If we don't know, obey --enable-cross-guesses.
73                  *)                  gl_cv_func_log1pl_ieee="$gl_cross_guess_normal" ;;
74                esac
75               ])
76             LIBS="$saved_LIBS"
77           ])
78         case "$gl_cv_func_log1pl_ieee" in
79           *yes) ;;
80           *) REPLACE_LOG1PL=1 ;;
81         esac
82       fi
83     ])
84   else
85     HAVE_LOG1PL=0
86     dnl Find libraries needed to link lib/log1pl.c.
87     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
88       LOG1PL_LIBM="$LOG1P_LIBM"
89     else
90       AC_REQUIRE([gl_FUNC_ISNANL])
91       AC_REQUIRE([gl_FUNC_LOGL])
92       AC_REQUIRE([gl_FUNC_ROUNDL])
93       LOG1PL_LIBM=
94       dnl Append $ISNANL_LIBM to LOG1PL_LIBM, avoiding gratuitous duplicates.
95       case " $LOG1PL_LIBM " in
96         *" $ISNANL_LIBM "*) ;;
97         *) LOG1PL_LIBM="$LOG1PL_LIBM $ISNANL_LIBM" ;;
98       esac
99       dnl Append $LOGL_LIBM to LOG1PL_LIBM, avoiding gratuitous duplicates.
100       case " $LOG1PL_LIBM " in
101         *" $LOGL_LIBM "*) ;;
102         *) LOG1PL_LIBM="$LOG1PL_LIBM $LOGL_LIBM" ;;
103       esac
104       dnl Append $ROUNDL_LIBM to LOG1PL_LIBM, avoiding gratuitous duplicates.
105       case " $LOG1PL_LIBM " in
106         *" $ROUNDL_LIBM "*) ;;
107         *) LOG1PL_LIBM="$LOG1PL_LIBM $ROUNDL_LIBM" ;;
108       esac
109     fi
110   fi
111   AC_SUBST([LOG1PL_LIBM])
114 dnl Test whether log1pl() works.
115 dnl On musl 1.2.2/{arm64,s390x} and NetBSD 10.0, the result is accurate to only
116 dnl 16 digits.
117 AC_DEFUN([gl_FUNC_LOG1PL_WORKS],
119   AC_REQUIRE([AC_PROG_CC])
120   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
121   AC_CACHE_CHECK([whether log1pl works], [gl_cv_func_log1pl_works],
122     [
123       AC_RUN_IFELSE(
124         [AC_LANG_SOURCE([[
125 #ifndef __NO_MATH_INLINES
126 # define __NO_MATH_INLINES 1 /* for glibc */
127 #endif
128 #include <float.h>
129 #include <math.h>
130 /* Override the values of <float.h>, like done in float.in.h.  */
131 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
132 # undef LDBL_MANT_DIG
133 # define LDBL_MANT_DIG   64
134 # undef LDBL_MIN_EXP
135 # define LDBL_MIN_EXP    (-16381)
136 # undef LDBL_MAX_EXP
137 # define LDBL_MAX_EXP    16384
138 #endif
139 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
140 # undef LDBL_MANT_DIG
141 # define LDBL_MANT_DIG   64
142 # undef LDBL_MIN_EXP
143 # define LDBL_MIN_EXP    (-16381)
144 # undef LDBL_MAX_EXP
145 # define LDBL_MAX_EXP    16384
146 #endif
147 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
148 # undef LDBL_MIN_EXP
149 # define LDBL_MIN_EXP DBL_MIN_EXP
150 #endif
151 #if defined __sgi && (LDBL_MANT_DIG >= 106)
152 # undef LDBL_MANT_DIG
153 # define LDBL_MANT_DIG 106
154 # if defined __GNUC__
155 #  undef LDBL_MIN_EXP
156 #  define LDBL_MIN_EXP DBL_MIN_EXP
157 # endif
158 #endif
159 #undef log1pl
160 extern
161 #ifdef __cplusplus
163 #endif
164 long double log1pl (long double);
165 static long double dummy (long double x) { return 0; }
166 int main (int argc, char *argv[])
168   long double (* volatile my_log1pl) (long double) = argc ? log1pl : dummy;
169   int result = 0;
170   /* This test fails on musl 1.2.2/arm64, musl 1.2.2/s390x, NetBSD 10.0.  */
171   {
172     const long double TWO_LDBL_MANT_DIG = /* 2^LDBL_MANT_DIG */
173       (long double) (1U << ((LDBL_MANT_DIG - 1) / 5))
174       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 1) / 5))
175       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 2) / 5))
176       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 3) / 5))
177       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 4) / 5));
178     long double x = 11.358L;
179     long double y = my_log1pl (x);
180     long double z = my_log1pl (- x / (1.0L + x));
181     long double err = (y + z) * TWO_LDBL_MANT_DIG;
182     if (!(err >= -900.0L && err <= 900.0L))
183       result |= 1;
184   }
186   return result;
188 ]])],
189         [gl_cv_func_log1pl_works=yes],
190         [gl_cv_func_log1pl_works=no],
191         [case "$host_os" in
192                                # Guess yes on glibc systems.
193            *-gnu* | gnu*)      gl_cv_func_log1pl_works="guessing yes" ;;
194                                # Guess no on musl systems.
195            *-musl* | midipix*) gl_cv_func_log1pl_works="guessing no" ;;
196                                # Guess no on NetBSD.
197            netbsd*)            gl_cv_func_log1pl_works="guessing no" ;;
198                                # Guess yes on native Windows.
199            mingw* | windows*)  gl_cv_func_log1pl_works="guessing yes" ;;
200                                # If we don't know, obey --enable-cross-guesses.
201            *)                  gl_cv_func_log1pl_works="$gl_cross_guess_normal" ;;
202          esac
203         ])
204     ])