immutable: Add tests.
[gnulib.git] / m4 / ceill.m4
blob18d65292efe133e2ea7aad2e5a36be53d622778d
1 # ceill.m4 serial 22
2 dnl Copyright (C) 2007, 2009-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_CEILL],
9   m4_divert_text([DEFAULTS], [gl_ceill_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
14   dnl Persuade glibc <math.h> to declare ceill().
15   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17   dnl Test whether ceill() is declared.
18   AC_CHECK_DECLS([ceill], , , [[#include <math.h>]])
19   if test "$ac_cv_have_decl_ceill" = yes; then
20     dnl Test whether ceill() can be used without libm.
21     gl_FUNC_CEILL_LIBS
22     if test "$CEILL_LIBM" = "?"; then
23       dnl Sun C 5.0 on Solaris declares ceill() and has it in the system-wide
24       dnl libm.so, but not in the libm.so that the compiler uses.
25       REPLACE_CEILL=1
26     fi
27     m4_ifdef([gl_FUNC_CEILL_IEEE], [
28       if test $gl_ceill_required = ieee && test $REPLACE_CEILL = 0; then
29         AC_CACHE_CHECK([whether ceill works according to ISO C 99 with IEC 60559],
30           [gl_cv_func_ceill_ieee],
31           [
32             save_LIBS="$LIBS"
33             LIBS="$LIBS $CEILL_LIBM"
34             AC_RUN_IFELSE(
35               [AC_LANG_SOURCE([[
36 #ifndef __NO_MATH_INLINES
37 # define __NO_MATH_INLINES 1 /* for glibc */
38 #endif
39 #include <math.h>
40 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
41 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
42 static long double dummy (long double f) { return 0; }
43 int main (int argc, char *argv[])
45   long double (* volatile my_ceill) (long double) = argc ? ceill : dummy;
46   /* Test whether ceill (-0.3L) is -0.0L.  */
47   if (signbitl (minus_zerol) && !signbitl (my_ceill (-0.3L)))
48     return 1;
49   return 0;
51               ]])],
52               [gl_cv_func_ceill_ieee=yes],
53               [gl_cv_func_ceill_ieee=no],
54               [case "$host_os" in
55                                 # Guess yes on glibc systems.
56                  *-gnu* | gnu*) gl_cv_func_ceill_ieee="guessing yes" ;;
57                                 # Guess yes on musl systems.
58                  *-musl*)       gl_cv_func_ceill_ieee="guessing yes" ;;
59                                 # Guess yes on native Windows.
60                  mingw*)        gl_cv_func_ceill_ieee="guessing yes" ;;
61                                 # If we don't know, obey --enable-cross-guesses.
62                  *)             gl_cv_func_ceill_ieee="$gl_cross_guess_normal" ;;
63                esac
64               ])
65             LIBS="$save_LIBS"
66           ])
67         case "$gl_cv_func_ceill_ieee" in
68           *yes) ;;
69           *) REPLACE_CEILL=1 ;;
70         esac
71       fi
72     ])
73   else
74     HAVE_DECL_CEILL=0
75   fi
76   dnl On OpenBSD 5.6 the system's native ceill() is buggy:
77   dnl it returns '0' for small values. Test against this anomaly.
78   if test $REPLACE_CEILL = 0 ; then
79     AC_CACHE_CHECK([whether ceill() works],
80       [gl_cv_func_ceill_works],
81       [save_LIBS="$LIBS"
82        LIBS="$CEILL_LIBM"
83        AC_RUN_IFELSE(
84          [AC_LANG_PROGRAM(
85             [[#include <math.h>
86 long double d = 0.3L;]],
87             [[return (!(ceill (d) == 1)); ]])],
88          [gl_cv_func_ceill_works=yes],
89          [gl_cv_func_ceill_works=no],
90          [case "$host_os" in
91             openbsd*) gl_cv_func_ceill_works="guessing no" ;;
92                       # Guess yes on native Windows.
93             mingw*)   gl_cv_func_ceill_works="guessing yes" ;;
94             *)        gl_cv_func_ceill_works="guessing yes" ;;
95           esac
96          ])
97        LIBS="$save_LIBS"
98       ])
99     case "$gl_cv_func_ceill_works" in
100       *yes) ;;
101       *) REPLACE_CEILL=1 ;;
102     esac
103   fi
104   if test $HAVE_DECL_CEILL = 0 || test $REPLACE_CEILL = 1; then
105     dnl Find libraries needed to link lib/ceill.c.
106     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
107       AC_REQUIRE([gl_FUNC_CEIL])
108       CEILL_LIBM="$CEIL_LIBM"
109     else
110       CEILL_LIBM=
111     fi
112   fi
113   AC_SUBST([CEILL_LIBM])
116 # Determines the libraries needed to get the ceill() function.
117 # Sets CEILL_LIBM.
118 AC_DEFUN([gl_FUNC_CEILL_LIBS],
120   gl_CACHE_VAL_SILENT([gl_cv_func_ceill_libm], [
121     gl_cv_func_ceill_libm=?
122     AC_LINK_IFELSE(
123       [AC_LANG_PROGRAM(
124          [[#ifndef __NO_MATH_INLINES
125            # define __NO_MATH_INLINES 1 /* for glibc */
126            #endif
127            #include <math.h>
128            long double (*funcptr) (long double) = ceill;
129            long double x;]],
130          [[x = funcptr(x) + ceill(x);]])],
131       [gl_cv_func_ceill_libm=])
132     if test "$gl_cv_func_ceill_libm" = "?"; then
133       save_LIBS="$LIBS"
134       LIBS="$LIBS -lm"
135       AC_LINK_IFELSE(
136         [AC_LANG_PROGRAM(
137            [[#ifndef __NO_MATH_INLINES
138              # define __NO_MATH_INLINES 1 /* for glibc */
139              #endif
140              #include <math.h>
141              long double (*funcptr) (long double) = ceill;
142              long double x;]],
143            [[x = funcptr(x) + ceill(x);]])],
144         [gl_cv_func_ceill_libm="-lm"])
145       LIBS="$save_LIBS"
146     fi
147   ])
148   CEILL_LIBM="$gl_cv_func_ceill_libm"