fchmod-tests, fchmodat tests, lchmod tests: Add more tests.
[gnulib.git] / m4 / floorf.m4
blobf521437848677f9a71adbfbf4b786ba9dc055e52
1 # floorf.m4 serial 18
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_FLOORF],
9   m4_divert_text([DEFAULTS], [gl_floorf_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   dnl Persuade glibc <math.h> to declare floorf().
12   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
13   dnl Test whether floorf() is declared.
14   AC_CHECK_DECLS([floorf], , , [[#include <math.h>]])
15   if test "$ac_cv_have_decl_floorf" = yes; then
16     dnl Test whether floorf() can be used without libm.
17     gl_FUNC_FLOORF_LIBS
18     if test "$FLOORF_LIBM" = "?"; then
19       dnl Sun C 5.0 on Solaris declares floorf() and has it in the system-wide
20       dnl libm.so, but not in the libm.so that the compiler uses.
21       REPLACE_FLOORF=1
22     fi
23     m4_ifdef([gl_FUNC_FLOORF_IEEE], [
24       if test $gl_floorf_required = ieee && test $REPLACE_FLOORF = 0; then
25         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
26         AC_CACHE_CHECK([whether floorf works according to ISO C 99 with IEC 60559],
27           [gl_cv_func_floorf_ieee],
28           [
29             save_LIBS="$LIBS"
30             LIBS="$LIBS $FLOORF_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_floorf) (float) = argc ? floorf : dummy;
43   /* Test whether floorf (-0.0f) is -0.0f.  */
44   if (signbitf (minus_zerof) && !signbitf (my_floorf (minus_zerof)))
45     return 1;
46   return 0;
48               ]])],
49               [gl_cv_func_floorf_ieee=yes],
50               [gl_cv_func_floorf_ieee=no],
51               [case "$host_os" in
52                                 # Guess yes on glibc systems.
53                  *-gnu* | gnu*) gl_cv_func_floorf_ieee="guessing yes" ;;
54                                 # Guess yes on musl systems.
55                  *-musl*)       gl_cv_func_floorf_ieee="guessing yes" ;;
56                                 # Guess yes on native Windows.
57                  mingw*)        gl_cv_func_floorf_ieee="guessing yes" ;;
58                                 # If we don't know, obey --enable-cross-guesses.
59                  *)             gl_cv_func_floorf_ieee="$gl_cross_guess_normal" ;;
60                esac
61               ])
62             LIBS="$save_LIBS"
63           ])
64         case "$gl_cv_func_floorf_ieee" in
65           *yes) ;;
66           *) REPLACE_FLOORF=1 ;;
67         esac
68       fi
69     ])
70   else
71     HAVE_DECL_FLOORF=0
72   fi
73   if test $HAVE_DECL_FLOORF = 0 || test $REPLACE_FLOORF = 1; then
74     dnl No libraries are needed to link lib/floorf.c.
75     FLOORF_LIBM=
76   fi
77   AC_SUBST([FLOORF_LIBM])
80 # Determines the libraries needed to get the floorf() function.
81 # Sets FLOORF_LIBM.
82 AC_DEFUN([gl_FUNC_FLOORF_LIBS],
84   gl_CACHE_VAL_SILENT([gl_cv_func_floorf_libm], [
85     gl_cv_func_floorf_libm=?
86     AC_LINK_IFELSE(
87       [AC_LANG_PROGRAM(
88          [[#ifndef __NO_MATH_INLINES
89            # define __NO_MATH_INLINES 1 /* for glibc */
90            #endif
91            #include <math.h>
92            float (*funcptr) (float) = floorf;
93            float x;]],
94          [[x = funcptr(x) + floorf(x);]])],
95       [gl_cv_func_floorf_libm=])
96     if test "$gl_cv_func_floorf_libm" = "?"; then
97       save_LIBS="$LIBS"
98       LIBS="$LIBS -lm"
99       AC_LINK_IFELSE(
100         [AC_LANG_PROGRAM(
101            [[#ifndef __NO_MATH_INLINES
102              # define __NO_MATH_INLINES 1 /* for glibc */
103              #endif
104              #include <math.h>
105              float (*funcptr) (float) = floorf;
106              float x;]],
107            [[x = funcptr(x) + floorf(x);]])],
108         [gl_cv_func_floorf_libm="-lm"])
109       LIBS="$save_LIBS"
110     fi
111   ])
112   FLOORF_LIBM="$gl_cv_func_floorf_libm"