Merge branch 'upstream' into stable
[gnulib.git] / m4 / roundl.m4
1 # roundl.m4 serial 8
2 dnl Copyright (C) 2007, 2009-2011 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.
6
7 AC_DEFUN([gl_FUNC_ROUNDL],
8 [
9   m4_divert_text([DEFAULTS], [gl_roundl_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   dnl Persuade glibc <math.h> to declare roundl().
12   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
13   AC_CHECK_DECLS([roundl], , , [#include <math.h>])
14   if test "$ac_cv_have_decl_roundl" = yes; then
15     gl_CHECK_MATH_LIB([ROUNDL_LIBM], [x = roundl (x);])
16     if test "$ROUNDL_LIBM" = missing; then
17       REPLACE_ROUNDL=1
18     fi
19     m4_ifdef([gl_FUNC_ROUNDL_IEEE], [
20       if test $gl_roundl_required = ieee && test $REPLACE_ROUNDL = 0; then
21         AC_CACHE_CHECK([whether roundl works according to ISO C 99 with IEC 60559],
22           [gl_cv_func_roundl_ieee],
23           [
24             save_LIBS="$LIBS"
25             LIBS="$LIBS $ROUNDL_LIBM"
26             AC_RUN_IFELSE(
27               [AC_LANG_SOURCE([[
28 #ifndef __NO_MATH_INLINES
29 # define __NO_MATH_INLINES 1 /* for glibc */
30 #endif
31 #include <math.h>
32 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
33 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
34 int main()
35 {
36   /* Test whether roundl (-0.0L) is -0.0L.  */
37   if (signbitl (minus_zerol) && !signbitl (roundl (minus_zerol)))
38     return 1;
39   return 0;
40 }
41               ]])],
42               [gl_cv_func_roundl_ieee=yes],
43               [gl_cv_func_roundl_ieee=no],
44               [gl_cv_func_roundl_ieee="guessing no"])
45             LIBS="$save_LIBS"
46           ])
47         case "$gl_cv_func_roundl_ieee" in
48           *yes) ;;
49           *) REPLACE_ROUNDL=1 ;;
50         esac
51       fi
52     ])
53   else
54     HAVE_DECL_ROUNDL=0
55   fi
56   if test $HAVE_DECL_ROUNDL = 0 || test $REPLACE_ROUNDL = 1; then
57     AC_LIBOBJ([roundl])
58     AC_CHECK_DECLS([ceill, floorl], , , [#include <math.h>])
59     if test "$ac_cv_have_decl_floorl" = yes \
60        && test "$ac_cv_have_decl_ceill" = yes; then
61       gl_FUNC_FLOORL_LIBS
62       gl_FUNC_CEILL_LIBS
63       if test "$FLOORL_LIBM" != '?' && test "$CEILL_LIBM" != '?'; then
64         AC_DEFINE([HAVE_FLOORL_AND_CEILL], [1],
65           [Define if the both the floorl() and ceill() functions exist.])
66         ROUNDL_LIBM=
67         dnl Append $FLOORL_LIBM to ROUNDL_LIBM, avoiding gratuitous duplicates.
68         case " $ROUNDL_LIBM " in
69           *" $FLOORL_LIBM "*) ;;
70           *) ROUNDL_LIBM="$ROUNDL_LIBM $FLOORL_LIBM" ;;
71         esac
72         dnl Append $CEILL_LIBM to ROUNDL_LIBM, avoiding gratuitous duplicates.
73         case " $ROUNDL_LIBM " in
74           *" $CEILL_LIBM "*) ;;
75           *) ROUNDL_LIBM="$ROUNDL_LIBM $CEILL_LIBM" ;;
76         esac
77       else
78         ROUNDL_LIBM=
79       fi
80     else
81       ROUNDL_LIBM=
82     fi
83   fi
84   AC_SUBST([ROUNDL_LIBM])
85 ])