libc-config: Fix __GNUC_PREREQ macro.
[gnulib.git] / m4 / floor.m4
blob0f9920040744d6bc868d96ea861e13bafc85afd8
1 # floor.m4 serial 9
2 dnl Copyright (C) 2007, 2009-2017 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 (*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*) gl_cv_func_floor_ieee="guessing yes" ;;
47                        # Guess yes on native Windows.
48                mingw*) gl_cv_func_floor_ieee="guessing yes" ;;
49                        # If we don't know, assume the worst.
50                *)      gl_cv_func_floor_ieee="guessing no" ;;
51              esac
52             ])
53           LIBS="$save_LIBS"
54         ])
55       case "$gl_cv_func_floor_ieee" in
56         *yes) ;;
57         *) REPLACE_FLOOR=1 ;;
58       esac
59     fi
60   ])
61   if test $REPLACE_FLOOR = 1; then
62     dnl No libraries are needed to link lib/floor.c.
63     FLOOR_LIBM=
64   fi
65   AC_SUBST([FLOOR_LIBM])
68 # Determines the libraries needed to get the floor() function.
69 # Sets FLOOR_LIBM.
70 AC_DEFUN([gl_FUNC_FLOOR_LIBS],
72   gl_CACHE_VAL_SILENT([gl_cv_func_floor_libm], [
73     gl_cv_func_floor_libm=?
74     AC_LINK_IFELSE(
75       [AC_LANG_PROGRAM(
76          [[#ifndef __NO_MATH_INLINES
77            # define __NO_MATH_INLINES 1 /* for glibc */
78            #endif
79            #include <math.h>
80            double x;]],
81          [[x = floor(x);]])],
82       [gl_cv_func_floor_libm=])
83     if test "$gl_cv_func_floor_libm" = "?"; then
84       save_LIBS="$LIBS"
85       LIBS="$LIBS -lm"
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              double x;]],
93            [[x = floor(x);]])],
94         [gl_cv_func_floor_libm="-lm"])
95       LIBS="$save_LIBS"
96     fi
97   ])
98   FLOOR_LIBM="$gl_cv_func_floor_libm"