summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2010-12-21 22:27:02 +0100
committerBruno Haible <bruno@clisp.org>2010-12-21 22:50:17 +0100
commit0f2428a839e2a11049eac5b8bf1d913be2a5dd56 (patch)
treeab957e480ca7bc0b903b6f61bb57e12a73f05360
parent8fe3f433681b195f1deef11bcb4ccec850597c81 (diff)
downloadgnulib-0f2428a839e2a11049eac5b8bf1d913be2a5dd56.tar.gz
New module 'roundl-ieee'.
* modules/roundl-ieee: New file. * m4/roundl.m4 (gl_FUNC_ROUNDL): If gl_FUNC_ROUNDL_IEEE is also used, test whether roundl works according to ISO C 99 with IEC 60559. * m4/roundl-ieee.m4: New file. * modules/roundl-ieee-tests: New file. * tests/test-roundl-ieee.c: New file, based on tests/test-roundl.c. * tests/test-roundl.c (main): Remove signbit tests. * modules/roundl-tests (Depends-on): Remove signbit. * doc/posix-functions/roundl.texi: Mention the new module.
-rw-r--r--ChangeLog13
-rw-r--r--doc/posix-functions/roundl.texi12
-rw-r--r--m4/roundl-ieee.m415
-rw-r--r--m4/roundl.m437
-rw-r--r--modules/roundl-ieee27
-rw-r--r--modules/roundl-ieee-tests15
-rw-r--r--modules/roundl-tests1
-rw-r--r--tests/test-roundl-ieee.c38
-rw-r--r--tests/test-roundl.c2
9 files changed, 154 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 0208548bbf..81c8e44ee3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2010-12-21 Bruno Haible <bruno@clisp.org>
+ New module 'roundl-ieee'.
+ * modules/roundl-ieee: New file.
+ * m4/roundl.m4 (gl_FUNC_ROUNDL): If gl_FUNC_ROUNDL_IEEE is also used,
+ test whether roundl works according to ISO C 99 with IEC 60559.
+ * m4/roundl-ieee.m4: New file.
+ * modules/roundl-ieee-tests: New file.
+ * tests/test-roundl-ieee.c: New file, based on tests/test-roundl.c.
+ * tests/test-roundl.c (main): Remove signbit tests.
+ * modules/roundl-tests (Depends-on): Remove signbit.
+ * doc/posix-functions/roundl.texi: Mention the new module.
+
+2010-12-21 Bruno Haible <bruno@clisp.org>
+
New module 'truncl-ieee'.
* modules/truncl-ieee: New file.
* modules/truncl-ieee-tests: New file.
diff --git a/doc/posix-functions/roundl.texi b/doc/posix-functions/roundl.texi
index 98bcfa64aa..5c3be85537 100644
--- a/doc/posix-functions/roundl.texi
+++ b/doc/posix-functions/roundl.texi
@@ -4,9 +4,9 @@
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/roundl.html}
-Gnulib module: roundl
+Gnulib module: roundl or roundl-ieee
-Portability problems fixed by Gnulib:
+Portability problems fixed by either Gnulib module @code{roundl} or @code{roundl-ieee}:
@itemize
@item
This function is missing on some platforms:
@@ -16,6 +16,14 @@ This function is not declared on some platforms:
glibc 2.8, OSF/1 5.1.
@end itemize
+Portability problems fixed by Gnulib module @code{roundl-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/roundl-ieee.m4 b/m4/roundl-ieee.m4
new file mode 100644
index 0000000000..b254726c3f
--- /dev/null
+++ b/m4/roundl-ieee.m4
@@ -0,0 +1,15 @@
+# roundl-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 roundl.m4 and not inlined in the
+dnl module description), so that gl_FUNC_ROUNDL can test whether 'aclocal' has
+dnl found uses of this macro.
+
+AC_DEFUN([gl_FUNC_ROUNDL_IEEE],
+[
+ m4_divert_text([INIT_PREPARE], [gl_roundl_required=ieee])
+ AC_REQUIRE([gl_FUNC_ROUNDL])
+])
diff --git a/m4/roundl.m4 b/m4/roundl.m4
index f7fe0e8b88..9d736112b7 100644
--- a/m4/roundl.m4
+++ b/m4/roundl.m4
@@ -1,4 +1,4 @@
-# roundl.m4 serial 7
+# roundl.m4 serial 8
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_ROUNDL],
[
+ m4_divert_text([DEFAULTS], [gl_roundl_required=plain])
AC_REQUIRE([gl_MATH_H_DEFAULTS])
dnl Persuade glibc <math.h> to declare roundl().
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
@@ -15,6 +16,40 @@ AC_DEFUN([gl_FUNC_ROUNDL],
if test "$ROUNDL_LIBM" = missing; then
REPLACE_ROUNDL=1
fi
+ m4_ifdef([gl_FUNC_ROUNDL_IEEE], [
+ if test $gl_roundl_required = ieee && test $REPLACE_ROUNDL = 0; then
+ AC_CACHE_CHECK([whether roundl works according to ISO C 99 with IEC 60559],
+ [gl_cv_func_roundl_ieee],
+ [
+ save_LIBS="$LIBS"
+ LIBS="$LIBS $ROUNDL_LIBM"
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
+#ifndef __NO_MATH_INLINES
+# define __NO_MATH_INLINES 1 /* for glibc */
+#endif
+#include <math.h>
+]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
+]gl_LONG_DOUBLE_SIGNBIT_CODE[
+int main()
+{
+ /* Test whether roundl (-0.0L) is -0.0L. */
+ if (signbitl (minus_zerol) && !signbitl (roundl (minus_zerol)))
+ return 1;
+ return 0;
+}
+ ]])],
+ [gl_cv_func_roundl_ieee=yes],
+ [gl_cv_func_roundl_ieee=no],
+ [gl_cv_func_roundl_ieee="guessing no"])
+ LIBS="$save_LIBS"
+ ])
+ case "$gl_cv_func_roundl_ieee" in
+ *yes) ;;
+ *) REPLACE_ROUNDL=1 ;;
+ esac
+ fi
+ ])
else
HAVE_DECL_ROUNDL=0
fi
diff --git a/modules/roundl-ieee b/modules/roundl-ieee
new file mode 100644
index 0000000000..e206259076
--- /dev/null
+++ b/modules/roundl-ieee
@@ -0,0 +1,27 @@
+Description:
+roundl() function according to ISO C 99 with IEC 60559.
+
+Files:
+m4/roundl-ieee.m4
+m4/minus-zero.m4
+m4/signbit.m4
+
+Depends-on:
+roundl
+
+configure.ac:
+gl_FUNC_ROUNDL_IEEE
+
+Makefile.am:
+
+Include:
+<math.h>
+
+Link:
+$(ROUNDL_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
diff --git a/modules/roundl-ieee-tests b/modules/roundl-ieee-tests
new file mode 100644
index 0000000000..47cdf60015
--- /dev/null
+++ b/modules/roundl-ieee-tests
@@ -0,0 +1,15 @@
+Files:
+tests/test-roundl-ieee.c
+tests/minus-zero.h
+tests/macros.h
+
+Depends-on:
+float
+signbit
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-roundl-ieee
+check_PROGRAMS += test-roundl-ieee
+test_roundl_ieee_LDADD = $(LDADD) @ROUNDL_LIBM@
diff --git a/modules/roundl-tests b/modules/roundl-tests
index 2561b3d444..f9bd46727e 100644
--- a/modules/roundl-tests
+++ b/modules/roundl-tests
@@ -9,7 +9,6 @@ Depends-on:
fpucw
isnanl-nolibm
float
-signbit
configure.ac:
diff --git a/tests/test-roundl-ieee.c b/tests/test-roundl-ieee.c
new file mode 100644
index 0000000000..ca4ac9ed7e
--- /dev/null
+++ b/tests/test-roundl-ieee.c
@@ -0,0 +1,38 @@
+/* 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 <config.h>
+
+#include <math.h>
+
+#include "fpucw.h"
+#include "minus-zero.h"
+#include "macros.h"
+
+int
+main ()
+{
+ DECL_LONG_DOUBLE_ROUNDING
+
+ BEGIN_LONG_DOUBLE_ROUNDING ();
+
+ /* Zero. */
+ ASSERT (!signbit (roundl (0.0L)));
+ ASSERT (!!signbit (roundl (minus_zerol)) == !!signbit (minus_zerol));
+
+ return 0;
+}
diff --git a/tests/test-roundl.c b/tests/test-roundl.c
index bdb8ddfec8..f06db8a017 100644
--- a/tests/test-roundl.c
+++ b/tests/test-roundl.c
@@ -42,9 +42,7 @@ main ()
/* Zero. */
ASSERT (roundl (0.0L) == 0.0L);
- ASSERT (!signbit (roundl (0.0L)));
ASSERT (roundl (minus_zerol) == 0.0L);
- ASSERT (!!signbit (minus_zerol) == !!signbit (roundl (minus_zerol)));
/* Positive numbers. */
ASSERT (roundl (0.3L) == 0.0L);
ASSERT (roundl (0.5L) == 1.0L);