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().
21 LIBS="$LIBS $LOG1P_LIBM"
22 AC_CHECK_FUNCS([log1pl])
24 if test $ac_cv_func_log1pl = yes; then
25 LOG1PL_LIBM="$LOG1P_LIBM"
28 LIBS="$LIBS $LOG1PL_LIBM"
31 case "$gl_cv_func_log1pl_works" in
33 *) REPLACE_LOG1PL=1 ;;
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],
43 LIBS="$LIBS $LOG1PL_LIBM"
46 #ifndef __NO_MATH_INLINES
47 # define __NO_MATH_INLINES 1 /* for glibc */
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)))
63 [gl_cv_func_log1pl_ieee=yes],
64 [gl_cv_func_log1pl_ieee=no],
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" ;;
78 case "$gl_cv_func_log1pl_ieee" in
80 *) REPLACE_LOG1PL=1 ;;
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"
90 AC_REQUIRE([gl_FUNC_ISNANL])
91 AC_REQUIRE([gl_FUNC_LOGL])
92 AC_REQUIRE([gl_FUNC_ROUNDL])
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" ;;
99 dnl Append $LOGL_LIBM to LOG1PL_LIBM, avoiding gratuitous duplicates.
100 case " $LOG1PL_LIBM " in
102 *) LOG1PL_LIBM="$LOG1PL_LIBM $LOGL_LIBM" ;;
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" ;;
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
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],
125 #ifndef __NO_MATH_INLINES
126 # define __NO_MATH_INLINES 1 /* for glibc */
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
135 # define LDBL_MIN_EXP (-16381)
137 # define LDBL_MAX_EXP 16384
139 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
140 # undef LDBL_MANT_DIG
141 # define LDBL_MANT_DIG 64
143 # define LDBL_MIN_EXP (-16381)
145 # define LDBL_MAX_EXP 16384
147 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
149 # define LDBL_MIN_EXP DBL_MIN_EXP
151 #if defined __sgi && (LDBL_MANT_DIG >= 106)
152 # undef LDBL_MANT_DIG
153 # define LDBL_MANT_DIG 106
154 # if defined __GNUC__
156 # define LDBL_MIN_EXP DBL_MIN_EXP
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;
170 /* This test fails on musl 1.2.2/arm64, musl 1.2.2/s390x, NetBSD 10.0. */
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))
189 [gl_cv_func_log1pl_works=yes],
190 [gl_cv_func_log1pl_works=no],
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" ;;