immutable: Add tests.
[gnulib.git] / m4 / ceilf.m4
blob0712155c4f233f0a3c283492dded09ce5f6fb5c0
1 # ceilf.m4 serial 19
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_CEILF],
9   m4_divert_text([DEFAULTS], [gl_ceilf_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   dnl Persuade glibc <math.h> to declare ceilf().
12   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
13   dnl Test whether ceilf() is declared.
14   AC_CHECK_DECLS([ceilf], , , [[#include <math.h>]])
15   if test "$ac_cv_have_decl_ceilf" = yes; then
16     dnl Test whether ceilf() can be used without libm.
17     gl_FUNC_CEILF_LIBS
18     if test "$CEILF_LIBM" = "?"; then
19       dnl Sun C 5.0 on Solaris declares ceilf() and has it in the system-wide
20       dnl libm.so, but not in the libm.so that the compiler uses.
21       REPLACE_CEILF=1
22     fi
23     m4_ifdef([gl_FUNC_CEILF_IEEE], [
24       if test $gl_ceilf_required = ieee && test $REPLACE_CEILF = 0; then
25         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
26         AC_CACHE_CHECK([whether ceilf works according to ISO C 99 with IEC 60559],
27           [gl_cv_func_ceilf_ieee],
28           [
29             save_LIBS="$LIBS"
30             LIBS="$LIBS $CEILF_LIBM"
31             AC_RUN_IFELSE(
32               [AC_LANG_SOURCE([[
33 #ifndef __NO_MATH_INLINES
34 # define __NO_MATH_INLINES 1 /* for glibc */
35 #endif
36 #include <math.h>
37 ]gl_FLOAT_MINUS_ZERO_CODE[
38 ]gl_FLOAT_SIGNBIT_CODE[
39 static float dummy (float f) { return 0; }
40 int main (int argc, char *argv[])
42   float (* volatile my_ceilf) (float) = argc ? ceilf : dummy;
43   int result = 0;
44   /* Test whether ceilf (-0.0f) is -0.0f.  */
45   if (signbitf (minus_zerof) && !signbitf (my_ceilf (minus_zerof)))
46     result |= 1;
47   /* Test whether ceilf (-0.3f) is -0.0f.  */
48   if (signbitf (-0.3f) && !signbitf (my_ceilf (-0.3f)))
49     result |= 2;
50   return result;
52               ]])],
53               [gl_cv_func_ceilf_ieee=yes],
54               [gl_cv_func_ceilf_ieee=no],
55               [case "$host_os" in
56                                 # Guess yes on glibc systems.
57                  *-gnu* | gnu*) gl_cv_func_ceilf_ieee="guessing yes" ;;
58                                 # Guess yes on musl systems.
59                  *-musl*)       gl_cv_func_ceilf_ieee="guessing yes" ;;
60                                 # Guess yes on native Windows.
61                  mingw*)        gl_cv_func_ceilf_ieee="guessing yes" ;;
62                                 # If we don't know, obey --enable-cross-guesses.
63                  *)             gl_cv_func_ceilf_ieee="$gl_cross_guess_normal" ;;
64                esac
65               ])
66             LIBS="$save_LIBS"
67           ])
68         case "$gl_cv_func_ceilf_ieee" in
69           *yes) ;;
70           *) REPLACE_CEILF=1 ;;
71         esac
72       fi
73     ])
74   else
75     HAVE_DECL_CEILF=0
76   fi
77   if test $HAVE_DECL_CEILF = 0 || test $REPLACE_CEILF = 1; then
78     dnl No libraries are needed to link lib/ceilf.c.
79     CEILF_LIBM=
80   fi
81   AC_SUBST([CEILF_LIBM])
84 # Determines the libraries needed to get the ceilf() function.
85 # Sets CEILF_LIBM.
86 AC_DEFUN([gl_FUNC_CEILF_LIBS],
88   gl_CACHE_VAL_SILENT([gl_cv_func_ceilf_libm], [
89     gl_cv_func_ceilf_libm=?
90     AC_LINK_IFELSE(
91       [AC_LANG_PROGRAM(
92          [[#ifndef __NO_MATH_INLINES
93            # define __NO_MATH_INLINES 1 /* for glibc */
94            #endif
95            #include <math.h>
96            float (*funcptr) (float) = ceilf;
97            float x;]],
98          [[x = funcptr(x) + ceilf(x);]])],
99       [gl_cv_func_ceilf_libm=])
100     if test "$gl_cv_func_ceilf_libm" = "?"; then
101       save_LIBS="$LIBS"
102       LIBS="$LIBS -lm"
103       AC_LINK_IFELSE(
104         [AC_LANG_PROGRAM(
105            [[#ifndef __NO_MATH_INLINES
106              # define __NO_MATH_INLINES 1 /* for glibc */
107              #endif
108              #include <math.h>
109              float (*funcptr) (float) = ceilf;
110              float x;]],
111            [[x = funcptr(x) + ceilf(x);]])],
112         [gl_cv_func_ceilf_libm="-lm"])
113       LIBS="$save_LIBS"
114     fi
115   ])
116   CEILF_LIBM="$gl_cv_func_ceilf_libm"