immutable: Add tests.
[gnulib.git] / m4 / floor.m4
blobe54d2c7f5d56219a95bdf1b17e1b32de6daaa404
1 # floor.m4 serial 14
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_FLOOR],
9   m4_divert_text([DEFAULTS], [gl_floor_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   dnl Test whether floor() can be used without libm.
12   gl_FUNC_FLOOR_LIBS
13   if test "$FLOOR_LIBM" = "?"; then
14     FLOOR_LIBM=
15   fi
16   m4_ifdef([gl_FUNC_FLOOR_IEEE], [
17     if test $gl_floor_required = ieee && test $REPLACE_FLOOR = 0; then
18       AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
19       AC_CACHE_CHECK([whether floor works according to ISO C 99 with IEC 60559],
20         [gl_cv_func_floor_ieee],
21         [
22           save_LIBS="$LIBS"
23           LIBS="$LIBS $FLOOR_LIBM"
24           AC_RUN_IFELSE(
25             [AC_LANG_SOURCE([[
26 #ifndef __NO_MATH_INLINES
27 # define __NO_MATH_INLINES 1 /* for glibc */
28 #endif
29 #include <math.h>
30 ]gl_DOUBLE_MINUS_ZERO_CODE[
31 ]gl_DOUBLE_SIGNBIT_CODE[
32 static double dummy (double f) { return 0; }
33 int main (int argc, char *argv[])
35   double (* volatile my_floor) (double) = argc ? floor : dummy;
36   /* Test whether floor (-0.0) is -0.0.  */
37   if (signbitd (minus_zerod) && !signbitd (my_floor (minus_zerod)))
38     return 1;
39   return 0;
41             ]])],
42             [gl_cv_func_floor_ieee=yes],
43             [gl_cv_func_floor_ieee=no],
44             [case "$host_os" in
45                               # Guess yes on glibc systems.
46                *-gnu* | gnu*) gl_cv_func_floor_ieee="guessing yes" ;;
47                               # Guess yes on musl systems.
48                *-musl*)       gl_cv_func_floor_ieee="guessing yes" ;;
49                               # Guess yes on native Windows.
50                mingw*)        gl_cv_func_floor_ieee="guessing yes" ;;
51                               # If we don't know, obey --enable-cross-guesses.
52                *)             gl_cv_func_floor_ieee="$gl_cross_guess_normal" ;;
53              esac
54             ])
55           LIBS="$save_LIBS"
56         ])
57       case "$gl_cv_func_floor_ieee" in
58         *yes) ;;
59         *) REPLACE_FLOOR=1 ;;
60       esac
61     fi
62   ])
63   if test $REPLACE_FLOOR = 1; then
64     dnl No libraries are needed to link lib/floor.c.
65     FLOOR_LIBM=
66   fi
67   AC_SUBST([FLOOR_LIBM])
70 # Determines the libraries needed to get the floor() function.
71 # Sets FLOOR_LIBM.
72 AC_DEFUN([gl_FUNC_FLOOR_LIBS],
74   gl_CACHE_VAL_SILENT([gl_cv_func_floor_libm], [
75     gl_cv_func_floor_libm=?
76     AC_LINK_IFELSE(
77       [AC_LANG_PROGRAM(
78          [[#ifndef __NO_MATH_INLINES
79            # define __NO_MATH_INLINES 1 /* for glibc */
80            #endif
81            #include <math.h>
82            double (*funcptr) (double) = floor;
83            double x;]],
84          [[x = funcptr(x) + floor(x);]])],
85       [gl_cv_func_floor_libm=])
86     if test "$gl_cv_func_floor_libm" = "?"; then
87       save_LIBS="$LIBS"
88       LIBS="$LIBS -lm"
89       AC_LINK_IFELSE(
90         [AC_LANG_PROGRAM(
91            [[#ifndef __NO_MATH_INLINES
92              # define __NO_MATH_INLINES 1 /* for glibc */
93              #endif
94              #include <math.h>
95              double (*funcptr) (double) = floor;
96              double x;]],
97            [[x = funcptr(x) + floor(x);]])],
98         [gl_cv_func_floor_libm="-lm"])
99       LIBS="$save_LIBS"
100     fi
101   ])
102   FLOOR_LIBM="$gl_cv_func_floor_libm"