Update Gnulib to v0.1-77-gd9361da
[bpt/guile.git] / m4 / floor.m4
CommitLineData
005de2e8 1# floor.m4 serial 8
5e69ceb7 2dnl Copyright (C) 2007, 2009-2014 Free Software Foundation, Inc.
b81eb646
LC
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_FUNC_FLOOR],
8[
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
005de2e8 18 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
b81eb646
LC
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[
231c0e0e
LC
32static double dummy (double f) { return 0; }
33int main (int argc, char *argv[])
b81eb646 34{
231c0e0e 35 double (*my_floor) (double) = argc ? floor : dummy;
b81eb646 36 /* Test whether floor (-0.0) is -0.0. */
231c0e0e 37 if (signbitd (minus_zerod) && !signbitd (my_floor (minus_zerod)))
b81eb646
LC
38 return 1;
39 return 0;
40}
41 ]])],
42 [gl_cv_func_floor_ieee=yes],
43 [gl_cv_func_floor_ieee=no],
005de2e8
LC
44 [case "$host_os" in
45 # Guess yes on glibc systems.
46 *-gnu*) gl_cv_func_floor_ieee="guessing yes" ;;
47 # If we don't know, assume the worst.
48 *) gl_cv_func_floor_ieee="guessing no" ;;
49 esac
50 ])
b81eb646
LC
51 LIBS="$save_LIBS"
52 ])
53 case "$gl_cv_func_floor_ieee" in
54 *yes) ;;
55 *) REPLACE_FLOOR=1 ;;
56 esac
57 fi
58 ])
59 if test $REPLACE_FLOOR = 1; then
3d458a81 60 dnl No libraries are needed to link lib/floor.c.
b81eb646
LC
61 FLOOR_LIBM=
62 fi
63 AC_SUBST([FLOOR_LIBM])
64])
65
66# Determines the libraries needed to get the floor() function.
67# Sets FLOOR_LIBM.
68AC_DEFUN([gl_FUNC_FLOOR_LIBS],
69[
70 gl_CACHE_VAL_SILENT([gl_cv_func_floor_libm], [
71 gl_cv_func_floor_libm=?
72 AC_LINK_IFELSE(
73 [AC_LANG_PROGRAM(
74 [[#ifndef __NO_MATH_INLINES
75 # define __NO_MATH_INLINES 1 /* for glibc */
76 #endif
77 #include <math.h>
78 double x;]],
79 [[x = floor(x);]])],
80 [gl_cv_func_floor_libm=])
81 if test "$gl_cv_func_floor_libm" = "?"; then
82 save_LIBS="$LIBS"
83 LIBS="$LIBS -lm"
84 AC_LINK_IFELSE(
85 [AC_LANG_PROGRAM(
86 [[#ifndef __NO_MATH_INLINES
87 # define __NO_MATH_INLINES 1 /* for glibc */
88 #endif
89 #include <math.h>
90 double x;]],
91 [[x = floor(x);]])],
92 [gl_cv_func_floor_libm="-lm"])
93 LIBS="$save_LIBS"
94 fi
95 ])
96 FLOOR_LIBM="$gl_cv_func_floor_libm"
97])