immutable: Add tests.
[gnulib.git] / m4 / cbrtl.m4
blob6c72ca85f671bf17c7dfab3056cfdd69e52bdbab
1 # cbrtl.m4 serial 10
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_CBRTL],
9   m4_divert_text([DEFAULTS], [gl_cbrtl_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12   AC_REQUIRE([gl_FUNC_CBRT])
14   dnl Persuade glibc <math.h> to declare cbrtl().
15   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17   dnl Test whether cbrtl() exists. Assume that cbrtl(), if it exists, is
18   dnl defined in the same library as cbrt().
19   save_LIBS="$LIBS"
20   LIBS="$LIBS $CBRT_LIBM"
21   AC_CHECK_FUNCS([cbrtl])
22   LIBS="$save_LIBS"
23   if test $ac_cv_func_cbrtl = yes; then
24     CBRTL_LIBM="$CBRT_LIBM"
25     dnl Also check whether it's declared.
26     dnl IRIX 6.5 has cbrtl() in libm but doesn't declare it in <math.h>.
27     AC_CHECK_DECL([cbrtl], , [HAVE_DECL_CBRTL=0], [[#include <math.h>]])
29     save_LIBS="$LIBS"
30     LIBS="$LIBS $CBRTL_LIBM"
31     gl_FUNC_CBRTL_WORKS
32     LIBS="$save_LIBS"
33     case "$gl_cv_func_cbrtl_works" in
34       *yes) ;;
35       *) REPLACE_CBRTL=1 ;;
36     esac
38     m4_ifdef([gl_FUNC_CBRTL_IEEE], [
39       if test $gl_cbrtl_required = ieee && test $REPLACE_CBRTL = 0; then
40         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
41         AC_CACHE_CHECK([whether cbrtl works according to ISO C 99 with IEC 60559],
42           [gl_cv_func_cbrtl_ieee],
43           [
44             save_LIBS="$LIBS"
45             LIBS="$LIBS $CBRTL_LIBM"
46             AC_RUN_IFELSE(
47               [AC_LANG_SOURCE([[
48 #ifndef __NO_MATH_INLINES
49 # define __NO_MATH_INLINES 1 /* for glibc */
50 #endif
51 #include <math.h>
52 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
53 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
54 static long double dummy (long double x) { return 0; }
55 int main (int argc, char *argv[])
57   extern
58   #ifdef __cplusplus
59   "C"
60   #endif
61   long double cbrtl (long double);
62   long double (* volatile my_cbrtl) (long double) = argc ? cbrtl : dummy;
63   long double f;
64   /* Test cbrtl(-0.0).
65      This test fails on IRIX 6.5.  */
66   f = my_cbrtl (minus_zerol);
67   if (!(f == 0.0L) || (signbitl (minus_zerol) && !signbitl (f)))
68     return 1;
69   return 0;
71               ]])],
72               [gl_cv_func_cbrtl_ieee=yes],
73               [gl_cv_func_cbrtl_ieee=no],
74               [case "$host_os" in
75                                 # Guess yes on glibc systems.
76                  *-gnu* | gnu*) gl_cv_func_cbrtl_ieee="guessing yes" ;;
77                                 # Guess yes on musl systems.
78                  *-musl*)       gl_cv_func_cbrtl_ieee="guessing yes" ;;
79                                 # Guess yes on native Windows.
80                  mingw*)        gl_cv_func_cbrtl_ieee="guessing yes" ;;
81                                 # If we don't know, obey --enable-cross-guesses.
82                  *)             gl_cv_func_cbrtl_ieee="$gl_cross_guess_normal" ;;
83                esac
84               ])
85             LIBS="$save_LIBS"
86           ])
87         case "$gl_cv_func_cbrtl_ieee" in
88           *yes) ;;
89           *) REPLACE_CBRTL=1 ;;
90         esac
91       fi
92     ])
93   else
94     HAVE_CBRTL=0
95     HAVE_DECL_CBRTL=0
96   fi
97   if test $HAVE_CBRTL = 0 || test $REPLACE_CBRTL = 1; then
98     dnl Find libraries needed to link lib/cbrtl.c.
99     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
100       CBRTL_LIBM="$CBRT_LIBM"
101     else
102       AC_REQUIRE([gl_FUNC_FREXPL])
103       AC_REQUIRE([gl_FUNC_LDEXPL])
104       CBRTL_LIBM=
105       dnl Append $FREXPL_LIBM to CBRTL_LIBM, avoiding gratuitous duplicates.
106       case " $CBRTL_LIBM " in
107         *" $FREXPL_LIBM "*) ;;
108         *) CBRTL_LIBM="$CBRTL_LIBM $FREXPL_LIBM" ;;
109       esac
110       dnl Append $LDEXPL_LIBM to CBRTL_LIBM, avoiding gratuitous duplicates.
111       case " $CBRTL_LIBM " in
112         *" $LDEXPL_LIBM "*) ;;
113         *) CBRTL_LIBM="$CBRTL_LIBM $LDEXPL_LIBM" ;;
114       esac
115     fi
116   fi
117   AC_SUBST([CBRTL_LIBM])
120 dnl Test whether cbrtl() works.
121 dnl On OpenBSD 5.1/SPARC, cbrtl(16.0L) is = 1.2599...
122 AC_DEFUN([gl_FUNC_CBRTL_WORKS],
124   AC_REQUIRE([AC_PROG_CC])
125   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
126   AC_CACHE_CHECK([whether cbrtl works], [gl_cv_func_cbrtl_works],
127     [
128       AC_RUN_IFELSE(
129         [AC_LANG_SOURCE([[
130 #include <math.h>
131 extern
132 #ifdef __cplusplus
134 #endif
135 long double cbrtl (long double);
136 volatile long double x;
137 long double y;
138 int main ()
140   x = 16.0L;
141   y = cbrtl (x);
142   if (y < 2.0L)
143     return 1;
144   return 0;
146 ]])],
147         [gl_cv_func_cbrtl_works=yes],
148         [gl_cv_func_cbrtl_works=no],
149         [case "$host_os" in
150            openbsd*) gl_cv_func_cbrtl_works="guessing no";;
151                      # Guess yes on native Windows.
152            mingw*)   gl_cv_func_cbrtl_works="guessing yes";;
153            *)        gl_cv_func_cbrtl_works="guessing yes";;
154          esac
155         ])
156     ])