immutable: Add tests.
[gnulib.git] / m4 / log1pl.m4
blob7d95aac4bf6e1c1cbc1ed68aa08e54a3c2c872af
1 # log1pl.m4 serial 8
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_LOG1PL],
9   m4_divert_text([DEFAULTS], [gl_log1pl_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12   AC_REQUIRE([gl_FUNC_LOG1P])
14   dnl Persuade glibc <math.h> to declare log1pl().
15   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17   dnl Test whether log1pl() exists. Assume that log1pl(), if it exists, is
18   dnl defined in the same library as log1p().
19   save_LIBS="$LIBS"
20   LIBS="$LIBS $LOG1P_LIBM"
21   AC_CHECK_FUNCS([log1pl])
22   LIBS="$save_LIBS"
23   if test $ac_cv_func_log1pl = yes; then
24     LOG1PL_LIBM="$LOG1P_LIBM"
25     m4_ifdef([gl_FUNC_LOG1PL_IEEE], [
26       if test $gl_log1pl_required = ieee && test $REPLACE_LOG1PL = 0; then
27         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
28         AC_CACHE_CHECK([whether log1pl works according to ISO C 99 with IEC 60559],
29           [gl_cv_func_log1pl_ieee],
30           [
31             save_LIBS="$LIBS"
32             LIBS="$LIBS $LOG1PL_LIBM"
33             AC_RUN_IFELSE(
34               [AC_LANG_SOURCE([[
35 #ifndef __NO_MATH_INLINES
36 # define __NO_MATH_INLINES 1 /* for glibc */
37 #endif
38 #include <math.h>
39 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
40 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
41 static long double dummy (long double x) { return 0; }
42 int main (int argc, char *argv[])
44   long double (* volatile my_log1pl) (long double) = argc ? log1pl : dummy;
45   /* This test fails on AIX 7.1, IRIX 6.5.  */
46   long double y = my_log1pl (minus_zerol);
47   if (!(y == 0.0L) || (signbitl (minus_zerol) && !signbitl (y)))
48     return 1;
49   return 0;
51               ]])],
52               [gl_cv_func_log1pl_ieee=yes],
53               [gl_cv_func_log1pl_ieee=no],
54               [case "$host_os" in
55                                 # Guess yes on glibc systems.
56                  *-gnu* | gnu*) gl_cv_func_log1pl_ieee="guessing yes" ;;
57                                 # Guess yes on musl systems.
58                  *-musl*)       gl_cv_func_log1pl_ieee="guessing yes" ;;
59                                 # Guess yes on native Windows.
60                  mingw*)        gl_cv_func_log1pl_ieee="guessing yes" ;;
61                                 # If we don't know, obey --enable-cross-guesses.
62                  *)             gl_cv_func_log1pl_ieee="$gl_cross_guess_normal" ;;
63                esac
64               ])
65             LIBS="$save_LIBS"
66           ])
67         case "$gl_cv_func_log1pl_ieee" in
68           *yes) ;;
69           *) REPLACE_LOG1PL=1 ;;
70         esac
71       fi
72     ])
73   else
74     HAVE_LOG1PL=0
75     dnl Find libraries needed to link lib/log1pl.c.
76     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
77       LOG1PL_LIBM="$LOG1P_LIBM"
78     else
79       AC_REQUIRE([gl_FUNC_ISNANL])
80       AC_REQUIRE([gl_FUNC_LOGL])
81       AC_REQUIRE([gl_FUNC_ROUNDL])
82       LOG1PL_LIBM=
83       dnl Append $ISNANL_LIBM to LOG1PL_LIBM, avoiding gratuitous duplicates.
84       case " $LOG1PL_LIBM " in
85         *" $ISNANL_LIBM "*) ;;
86         *) LOG1PL_LIBM="$LOG1PL_LIBM $ISNANL_LIBM" ;;
87       esac
88       dnl Append $LOGL_LIBM to LOG1PL_LIBM, avoiding gratuitous duplicates.
89       case " $LOG1PL_LIBM " in
90         *" $LOGL_LIBM "*) ;;
91         *) LOG1PL_LIBM="$LOG1PL_LIBM $LOGL_LIBM" ;;
92       esac
93       dnl Append $ROUNDL_LIBM to LOG1PL_LIBM, avoiding gratuitous duplicates.
94       case " $LOG1PL_LIBM " in
95         *" $ROUNDL_LIBM "*) ;;
96         *) LOG1PL_LIBM="$LOG1PL_LIBM $ROUNDL_LIBM" ;;
97       esac
98     fi
99   fi
100   AC_SUBST([LOG1PL_LIBM])