added missing dependencies to fix failing unistr/ tests
[gnulib.git] / m4 / roundf.m4
1 # roundf.m4 serial 9
2 dnl Copyright (C) 2007-2010 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_ROUNDF],
8 [
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   dnl Persuade glibc <math.h> to declare roundf().
11   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
12   AC_CHECK_DECLS([roundf], , , [#include <math.h>])
13   if test "$ac_cv_have_decl_roundf" = yes; then
14     gl_CHECK_MATH_LIB([ROUNDF_LIBM], [x = roundf (x);])
15     if test "$ROUNDF_LIBM" != missing; then
16       dnl Test whether roundf() produces correct results. On mingw, for
17       dnl x = 1/2 - 2^-25, the system's roundf() returns a wrong result.
18       AC_REQUIRE([AC_PROG_CC])
19       AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
20       AC_CACHE_CHECK([whether roundf works], [gl_cv_func_roundf_works],
21         [
22           save_LIBS="$LIBS"
23           LIBS="$LIBS $ROUNDF_LIBM"
24           AC_RUN_IFELSE([AC_LANG_SOURCE([[
25 #include <float.h>
26 #include <math.h>
27 int main()
28 {
29   /* 2^FLT_MANT_DIG.  */
30   static const float TWO_MANT_DIG =
31     /* Assume FLT_MANT_DIG <= 3 * 31.
32        Use the identity  n = floor(n/3) + floor((n+1)/3) + floor((n+2)/3).  */
33     (float) (1U << (FLT_MANT_DIG / 3))
34     * (float) (1U << ((FLT_MANT_DIG + 1) / 3))
35     * (float) (1U << ((FLT_MANT_DIG + 2) / 3));
36   volatile float x = 0.5f - 0.5f / TWO_MANT_DIG;
37   exit (x < 0.5f && roundf (x) != 0.0f);
38 }]])], [gl_cv_func_roundf_works=yes], [gl_cv_func_roundf_works=no],
39           [case "$host_os" in
40              mingw*) gl_cv_func_roundf_works="guessing no";;
41              *)      gl_cv_func_roundf_works="guessing yes";;
42            esac
43           ])
44           LIBS="$save_LIBS"
45         ])
46       case "$gl_cv_func_roundf_works" in
47         *no) ROUNDF_LIBM=missing ;;
48       esac
49     fi
50     if test "$ROUNDF_LIBM" = missing; then
51       REPLACE_ROUNDF=1
52     fi
53   else
54     HAVE_DECL_ROUNDF=0
55   fi
56   if test $HAVE_DECL_ROUNDF = 0 || test $REPLACE_ROUNDF = 1; then
57     AC_LIBOBJ([roundf])
58     AC_CHECK_DECLS([ceilf, floorf], , , [#include <math.h>])
59     if test "$ac_cv_have_decl_floorf" = yes \
60        && test "$ac_cv_have_decl_ceilf" = yes; then
61       gl_FUNC_FLOORF_LIBS
62       gl_FUNC_CEILF_LIBS
63       if test "$FLOORF_LIBM" != '?' && test "$CEILF_LIBM" != '?'; then
64         AC_DEFINE([HAVE_FLOORF_AND_CEILF], [1],
65           [Define if the both the floorf() and ceilf() functions exist.])
66         ROUNDF_LIBM=
67         dnl Append $FLOORF_LIBM to ROUNDF_LIBM, avoiding gratuitous duplicates.
68         case " $ROUNDF_LIBM " in
69           *" $FLOORF_LIBM "*) ;;
70           *) ROUNDF_LIBM="$ROUNDF_LIBM $FLOORF_LIBM" ;;
71         esac
72         dnl Append $CEILF_LIBM to ROUNDF_LIBM, avoiding gratuitous duplicates.
73         case " $ROUNDF_LIBM " in
74           *" $CEILF_LIBM "*) ;;
75           *) ROUNDF_LIBM="$ROUNDF_LIBM $CEILF_LIBM" ;;
76         esac
77       else
78         ROUNDF_LIBM=
79       fi
80     else
81       ROUNDF_LIBM=
82     fi
83   fi
84   AC_SUBST([ROUNDF_LIBM])
85 ])