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.
7 AC_DEFUN([gl_FUNC_ROUNDF],
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],
23 LIBS="$LIBS $ROUNDF_LIBM"
24 AC_RUN_IFELSE([AC_LANG_SOURCE([[
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],
40 mingw*) gl_cv_func_roundf_works="guessing no";;
41 *) gl_cv_func_roundf_works="guessing yes";;
46 case "$gl_cv_func_roundf_works" in
47 *no) ROUNDF_LIBM=missing ;;
50 if test "$ROUNDF_LIBM" = missing; then
56 if test $HAVE_DECL_ROUNDF = 0 || test $REPLACE_ROUNDF = 1; then
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
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.])
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" ;;
72 dnl Append $CEILF_LIBM to ROUNDF_LIBM, avoiding gratuitous duplicates.
73 case " $ROUNDF_LIBM " in
75 *) ROUNDF_LIBM="$ROUNDF_LIBM $CEILF_LIBM" ;;
84 AC_SUBST([ROUNDF_LIBM])