2 dnl Copyright (C) 2007-2009 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);])
16 if test "$ac_cv_have_decl_roundf" = yes && test "$ROUNDF_LIBM" != missing; then
17 dnl Test whether roundf() produces correct results. On mingw, for
18 dnl x = 1/2 - 2^-25, the system's roundf() returns a wrong result.
19 AC_REQUIRE([AC_PROG_CC])
20 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
21 AC_CACHE_CHECK([whether roundf works], [gl_cv_func_roundf_works],
24 LIBS="$LIBS $ROUNDF_LIBM"
31 static const float TWO_MANT_DIG =
32 /* Assume FLT_MANT_DIG <= 3 * 31.
33 Use the identity n = floor(n/3) + floor((n+1)/3) + floor((n+2)/3). */
34 (float) (1U << (FLT_MANT_DIG / 3))
35 * (float) (1U << ((FLT_MANT_DIG + 1) / 3))
36 * (float) (1U << ((FLT_MANT_DIG + 2) / 3));
37 volatile float x = 0.5f - 0.5f / TWO_MANT_DIG;
38 exit (x < 0.5f && roundf (x) != 0.0f);
39 }], [gl_cv_func_roundf_works=yes], [gl_cv_func_roundf_works=no],
41 mingw*) gl_cv_func_roundf_works="guessing no";;
42 *) gl_cv_func_roundf_works="guessing yes";;
47 case "$gl_cv_func_roundf_works" in
48 *no) ROUNDF_LIBM=missing ;;
51 if test "$ac_cv_have_decl_roundf" != yes || test "$ROUNDF_LIBM" = missing; then
54 AC_CHECK_DECLS([ceilf, floorf], , , [#include <math.h>])
55 if test "$ac_cv_have_decl_floorf" = yes \
56 && test "$ac_cv_have_decl_ceilf" = yes; then
59 if test "$FLOORF_LIBM" != '?' && test "$CEILF_LIBM" != '?'; then
60 AC_DEFINE([HAVE_FLOORF_AND_CEILF], [1],
61 [Define if the both the floorf() and ceilf() functions exist.])
62 ROUNDF_LIBM="$FLOORF_LIBM $CEILF_LIBM"
70 AC_SUBST([ROUNDF_LIBM])