Merge remote-tracking branch 'origin/stable-2.0'
[bpt/guile.git] / m4 / floor.m4
CommitLineData
231c0e0e 1# floor.m4 serial 7
f0007cad 2dnl Copyright (C) 2007, 2009-2012 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
18 AC_CACHE_CHECK([whether floor works according to ISO C 99 with IEC 60559],
19 [gl_cv_func_floor_ieee],
20 [
21 save_LIBS="$LIBS"
22 LIBS="$LIBS $FLOOR_LIBM"
23 AC_RUN_IFELSE(
24 [AC_LANG_SOURCE([[
25#ifndef __NO_MATH_INLINES
26# define __NO_MATH_INLINES 1 /* for glibc */
27#endif
28#include <math.h>
29]gl_DOUBLE_MINUS_ZERO_CODE[
30]gl_DOUBLE_SIGNBIT_CODE[
231c0e0e
LC
31static double dummy (double f) { return 0; }
32int main (int argc, char *argv[])
b81eb646 33{
231c0e0e 34 double (*my_floor) (double) = argc ? floor : dummy;
b81eb646 35 /* Test whether floor (-0.0) is -0.0. */
231c0e0e 36 if (signbitd (minus_zerod) && !signbitd (my_floor (minus_zerod)))
b81eb646
LC
37 return 1;
38 return 0;
39}
40 ]])],
41 [gl_cv_func_floor_ieee=yes],
42 [gl_cv_func_floor_ieee=no],
43 [gl_cv_func_floor_ieee="guessing no"])
44 LIBS="$save_LIBS"
45 ])
46 case "$gl_cv_func_floor_ieee" in
47 *yes) ;;
48 *) REPLACE_FLOOR=1 ;;
49 esac
50 fi
51 ])
52 if test $REPLACE_FLOOR = 1; then
3d458a81 53 dnl No libraries are needed to link lib/floor.c.
b81eb646
LC
54 FLOOR_LIBM=
55 fi
56 AC_SUBST([FLOOR_LIBM])
57])
58
59# Determines the libraries needed to get the floor() function.
60# Sets FLOOR_LIBM.
61AC_DEFUN([gl_FUNC_FLOOR_LIBS],
62[
63 gl_CACHE_VAL_SILENT([gl_cv_func_floor_libm], [
64 gl_cv_func_floor_libm=?
65 AC_LINK_IFELSE(
66 [AC_LANG_PROGRAM(
67 [[#ifndef __NO_MATH_INLINES
68 # define __NO_MATH_INLINES 1 /* for glibc */
69 #endif
70 #include <math.h>
71 double x;]],
72 [[x = floor(x);]])],
73 [gl_cv_func_floor_libm=])
74 if test "$gl_cv_func_floor_libm" = "?"; then
75 save_LIBS="$LIBS"
76 LIBS="$LIBS -lm"
77 AC_LINK_IFELSE(
78 [AC_LANG_PROGRAM(
79 [[#ifndef __NO_MATH_INLINES
80 # define __NO_MATH_INLINES 1 /* for glibc */
81 #endif
82 #include <math.h>
83 double x;]],
84 [[x = floor(x);]])],
85 [gl_cv_func_floor_libm="-lm"])
86 LIBS="$save_LIBS"
87 fi
88 ])
89 FLOOR_LIBM="$gl_cv_func_floor_libm"
90])