From 9b144e908f361bc95b309fd33bfa0bc09ae55cc7 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 21 Dec 2010 18:55:59 +0100 Subject: [PATCH] New module 'round-ieee'. * modules/round-ieee: New file. * m4/round.m4 (gl_FUNC_ROUND): If gl_FUNC_ROUND_IEEE is also used, test whether round works according to ISO C 99 with IEC 60559. * m4/round-ieee.m4: New file. * modules/round-ieee-tests: New file. * tests/test-round-ieee.c: New file, based on tests/test-roundf-ieee.c. * tests/test-round1.c (main): Remove signbit tests. * modules/round-tests (Depends-on): Remove 'signbit'. * doc/posix-functions/round.texi: Mention the new module. --- ChangeLog | 13 +++++++++++++ doc/posix-functions/round.texi | 12 ++++++++++-- m4/round-ieee.m4 | 15 +++++++++++++++ m4/round.m4 | 37 ++++++++++++++++++++++++++++++++++++- modules/round-ieee | 27 +++++++++++++++++++++++++++ modules/round-ieee-tests | 15 +++++++++++++++ modules/round-tests | 1 - tests/test-round-ieee.c | 33 +++++++++++++++++++++++++++++++++ tests/test-round1.c | 2 -- 9 files changed, 149 insertions(+), 6 deletions(-) create mode 100644 m4/round-ieee.m4 create mode 100644 modules/round-ieee create mode 100644 modules/round-ieee-tests create mode 100644 tests/test-round-ieee.c diff --git a/ChangeLog b/ChangeLog index 22c775296..2a7c2d2e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2010-12-21 Bruno Haible + New module 'round-ieee'. + * modules/round-ieee: New file. + * m4/round.m4 (gl_FUNC_ROUND): If gl_FUNC_ROUND_IEEE is also used, test + whether round works according to ISO C 99 with IEC 60559. + * m4/round-ieee.m4: New file. + * modules/round-ieee-tests: New file. + * tests/test-round-ieee.c: New file, based on tests/test-roundf-ieee.c. + * tests/test-round1.c (main): Remove signbit tests. + * modules/round-tests (Depends-on): Remove 'signbit'. + * doc/posix-functions/round.texi: Mention the new module. + +2010-12-21 Bruno Haible + New module 'trunc-ieee'. * modules/trunc-ieee: New file. * m4/trunc.m4 (gl_FUNC_TRUNC): If gl_FUNC_TRUNC_IEEE is also used, test diff --git a/doc/posix-functions/round.texi b/doc/posix-functions/round.texi index 913490e4a..cf3189b31 100644 --- a/doc/posix-functions/round.texi +++ b/doc/posix-functions/round.texi @@ -4,9 +4,9 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/round.html} -Gnulib module: round +Gnulib module: round or round-ieee -Portability problems fixed by Gnulib: +Portability problems fixed by either Gnulib module @code{round} or @code{round-ieee}: @itemize @item This function is missing on some platforms: @@ -19,6 +19,14 @@ This functions returns a wrong result for x = 1/2 - 2^-54 on some platforms: NetBSD 3.0, AIX 7.1. @end itemize +Portability problems fixed by Gnulib module @code{round-ieee}: +@itemize +@item +This function returns a positive zero for a minus zero argument +on some platforms: +OSF/1 5.1. +@end itemize + Portability problems not fixed by Gnulib: @itemize @end itemize diff --git a/m4/round-ieee.m4 b/m4/round-ieee.m4 new file mode 100644 index 000000000..68830b91b --- /dev/null +++ b/m4/round-ieee.m4 @@ -0,0 +1,15 @@ +# round-ieee.m4 serial 1 +dnl Copyright (C) 2010 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl This macro is in a separate file (not in round.m4 and not inlined in the +dnl module description), so that gl_FUNC_ROUND can test whether 'aclocal' has +dnl found uses of this macro. + +AC_DEFUN([gl_FUNC_ROUND_IEEE], +[ + m4_divert_text([INIT_PREPARE], [gl_round_required=ieee]) + AC_REQUIRE([gl_FUNC_ROUND]) +]) diff --git a/m4/round.m4 b/m4/round.m4 index 1d1b91c1a..5f19c5aa6 100644 --- a/m4/round.m4 +++ b/m4/round.m4 @@ -1,4 +1,4 @@ -# round.m4 serial 9 +# round.m4 serial 10 dnl Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -6,6 +6,7 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_ROUND], [ + m4_divert_text([DEFAULTS], [gl_round_required=plain]) AC_REQUIRE([gl_MATH_H_DEFAULTS]) dnl Persuade glibc to declare round(). AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) @@ -53,6 +54,40 @@ int main() if test "$ROUND_LIBM" = missing; then REPLACE_ROUND=1 fi + m4_ifdef([gl_FUNC_ROUND_IEEE], [ + if test $gl_round_required = ieee && test $REPLACE_ROUND = 0; then + AC_CACHE_CHECK([whether round works according to ISO C 99 with IEC 60559], + [gl_cv_func_round_ieee], + [ + save_LIBS="$LIBS" + LIBS="$LIBS $ROUND_LIBM" + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#ifndef __NO_MATH_INLINES +# define __NO_MATH_INLINES 1 /* for glibc */ +#endif +#include +]gl_DOUBLE_MINUS_ZERO_CODE[ +]gl_DOUBLE_SIGNBIT_CODE[ +int main() +{ + /* Test whether round (-0.0) is -0.0. */ + if (signbitd (minus_zerod) && !signbitd (round (minus_zerod))) + return 1; + return 0; +} + ]])], + [gl_cv_func_round_ieee=yes], + [gl_cv_func_round_ieee=no], + [gl_cv_func_round_ieee="guessing no"]) + LIBS="$save_LIBS" + ]) + case "$gl_cv_func_round_ieee" in + *yes) ;; + *) REPLACE_ROUND=1 ;; + esac + fi + ]) else HAVE_DECL_ROUND=0 fi diff --git a/modules/round-ieee b/modules/round-ieee new file mode 100644 index 000000000..3cdedca72 --- /dev/null +++ b/modules/round-ieee @@ -0,0 +1,27 @@ +Description: +round() function according to ISO C 99 with IEC 60559. + +Files: +m4/round-ieee.m4 +m4/minus-zero.m4 +m4/signbit.m4 + +Depends-on: +round + +configure.ac: +gl_FUNC_ROUND_IEEE + +Makefile.am: + +Include: + + +Link: +$(ROUND_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/round-ieee-tests b/modules/round-ieee-tests new file mode 100644 index 000000000..6e32da51b --- /dev/null +++ b/modules/round-ieee-tests @@ -0,0 +1,15 @@ +Files: +tests/test-round-ieee.c +tests/minus-zero.h +tests/macros.h + +Depends-on: +float +signbit + +configure.ac: + +Makefile.am: +TESTS += test-round-ieee +check_PROGRAMS += test-round-ieee +test_round_ieee_LDADD = $(LDADD) @ROUND_LIBM@ diff --git a/modules/round-tests b/modules/round-tests index cf3d9604f..9e154c8cc 100644 --- a/modules/round-tests +++ b/modules/round-tests @@ -8,7 +8,6 @@ tests/macros.h Depends-on: isnand-nolibm -signbit stdbool stdint verify diff --git a/tests/test-round-ieee.c b/tests/test-round-ieee.c new file mode 100644 index 000000000..0d5ad86df --- /dev/null +++ b/tests/test-round-ieee.c @@ -0,0 +1,33 @@ +/* Test of rounding to nearest, breaking ties away from zero. + Copyright (C) 2010 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +#include + +#include "minus-zero.h" +#include "macros.h" + +int +main () +{ + /* Zero. */ + ASSERT (!signbit (round (0.0))); + ASSERT (!!signbit (round (minus_zerod)) == !!signbit (minus_zerod)); + + return 0; +} diff --git a/tests/test-round1.c b/tests/test-round1.c index 4711a7436..86fd1de7a 100644 --- a/tests/test-round1.c +++ b/tests/test-round1.c @@ -35,9 +35,7 @@ main () { /* Zero. */ ASSERT (round (0.0) == 0.0); - ASSERT (!signbit (round (0.0))); ASSERT (round (minus_zerod) == 0.0); - ASSERT (!!signbit (minus_zerod) == !!signbit (round (minus_zerod))); /* Positive numbers. */ ASSERT (round (0.3) == 0.0); ASSERT (round (0.5) == 1.0); -- 2.11.0