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 m4_divert_text([DEFAULTS], [gl_roundf_required=plain])
10 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 dnl Persuade glibc <math.h> to declare roundf().
12 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
13 AC_CHECK_DECLS([roundf], , , [#include <math.h>])
14 if test "$ac_cv_have_decl_roundf" = yes; then
15 gl_CHECK_MATH_LIB([ROUNDF_LIBM], [x = roundf (x);])
16 if 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"
25 AC_RUN_IFELSE([AC_LANG_SOURCE([[
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 "$ROUNDF_LIBM" = missing; then
54 m4_ifdef([gl_FUNC_ROUNDF_IEEE], [
55 if test $gl_roundf_required = ieee && test $REPLACE_ROUNDF = 0; then
56 AC_CACHE_CHECK([whether roundf works according to ISO C 99 with IEC 60559],
57 [gl_cv_func_roundf_ieee],
60 LIBS="$LIBS $ROUNDF_LIBM"
63 #ifndef __NO_MATH_INLINES
64 # define __NO_MATH_INLINES 1 /* for glibc */
67 ]gl_FLOAT_MINUS_ZERO_CODE[
68 ]gl_FLOAT_SIGNBIT_CODE[
71 /* Test whether roundf (-0.0f) is -0.0f. */
72 if (signbitf (minus_zerof) && !signbitf (roundf (minus_zerof)))
77 [gl_cv_func_roundf_ieee=yes],
78 [gl_cv_func_roundf_ieee=no],
79 [gl_cv_func_roundf_ieee="guessing no"])
82 case "$gl_cv_func_roundf_ieee" in
84 *) REPLACE_ROUNDF=1 ;;
91 if test $HAVE_DECL_ROUNDF = 0 || test $REPLACE_ROUNDF = 1; then
93 AC_CHECK_DECLS([ceilf, floorf], , , [#include <math.h>])
94 if test "$ac_cv_have_decl_floorf" = yes \
95 && test "$ac_cv_have_decl_ceilf" = yes; then
98 if test "$FLOORF_LIBM" != '?' && test "$CEILF_LIBM" != '?'; then
99 AC_DEFINE([HAVE_FLOORF_AND_CEILF], [1],
100 [Define if the both the floorf() and ceilf() functions exist.])
102 dnl Append $FLOORF_LIBM to ROUNDF_LIBM, avoiding gratuitous duplicates.
103 case " $ROUNDF_LIBM " in
104 *" $FLOORF_LIBM "*) ;;
105 *) ROUNDF_LIBM="$ROUNDF_LIBM $FLOORF_LIBM" ;;
107 dnl Append $CEILF_LIBM to ROUNDF_LIBM, avoiding gratuitous duplicates.
108 case " $ROUNDF_LIBM " in
109 *" $CEILF_LIBM "*) ;;
110 *) ROUNDF_LIBM="$ROUNDF_LIBM $CEILF_LIBM" ;;
119 AC_SUBST([ROUNDF_LIBM])