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