New module 'roundf-ieee'.
authorBruno Haible <bruno@clisp.org>
Tue, 21 Dec 2010 14:58:00 +0000 (15:58 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 21 Dec 2010 21:46:47 +0000 (22:46 +0100)
* modules/roundf-ieee: New file.
* m4/roundf.m4 (gl_FUNC_ROUNDF): If gl_FUNC_ROUNDF_IEEE is also used,
test whether roundf works according to ISO C 99 with IEC 60559.
* m4/roundf-ieee.m4: New file.
* modules/roundf-ieee-tests: New file.
* tests/test-roundf-ieee.c: New file, based on tests/test-roundf1.c.
* tests/test-roundf1.c (main): Remove signbit tests.
* modules/roundf-tests (Depends-on): Remove 'signbit'.
* doc/posix-functions/roundf.texi: Mention the new module.

ChangeLog
doc/posix-functions/roundf.texi
m4/roundf-ieee.m4 [new file with mode: 0644]
m4/roundf.m4
modules/roundf-ieee [new file with mode: 0644]
modules/roundf-ieee-tests [new file with mode: 0644]
modules/roundf-tests
tests/test-roundf-ieee.c [new file with mode: 0644]
tests/test-roundf1.c

index b7331717c7813a010b6f30a8916aaccf6cf858c2..188c1e3869724fed5e9b92423abf2d77e7c27f89 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2010-12-21  Bruno Haible  <bruno@clisp.org>
+
+       New module 'roundf-ieee'.
+       * modules/roundf-ieee: New file.
+       * m4/roundf.m4 (gl_FUNC_ROUNDF): If gl_FUNC_ROUNDF_IEEE is also used,
+       test whether roundf works according to ISO C 99 with IEC 60559.
+       * m4/roundf-ieee.m4: New file.
+       * modules/roundf-ieee-tests: New file.
+       * tests/test-roundf-ieee.c: New file, based on tests/test-roundf1.c.
+       * tests/test-roundf1.c (main): Remove signbit tests.
+       * modules/roundf-tests (Depends-on): Remove 'signbit'.
+       * doc/posix-functions/roundf.texi: Mention the new module.
+
 2010-12-21  Bruno Haible  <bruno@clisp.org>
 
        New module 'truncf-ieee'.
index e52a7962c760fbe7f796689df78ee734c7b67d00..c4fb602916d7839c0c3dfc9552a724c2befaebc1 100644 (file)
@@ -4,9 +4,9 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/roundf.html}
 
-Gnulib module: roundf
+Gnulib module: roundf or roundf-ieee
 
-Portability problems fixed by Gnulib:
+Portability problems fixed by either Gnulib module @code{roundf} or @code{roundf-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^-25 on some platforms:
 mingw.
 @end itemize
 
+Portability problems fixed by Gnulib module @code{roundf-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/roundf-ieee.m4 b/m4/roundf-ieee.m4
new file mode 100644 (file)
index 0000000..7184a98
--- /dev/null
@@ -0,0 +1,15 @@
+# roundf-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 roundf.m4 and not inlined in the
+dnl module description), so that gl_FUNC_ROUNDF can test whether 'aclocal' has
+dnl found uses of this macro.
+
+AC_DEFUN([gl_FUNC_ROUNDF_IEEE],
+[
+  m4_divert_text([INIT_PREPARE], [gl_roundf_required=ieee])
+  AC_REQUIRE([gl_FUNC_ROUNDF])
+])
index a105760d2b52cdce4dc02500d4d0de03fff2e761..0a0aa68c205e3cda2576b3962e884486bd729e52 100644 (file)
@@ -1,4 +1,4 @@
-# roundf.m4 serial 9
+# roundf.m4 serial 10
 dnl Copyright (C) 2007-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_ROUNDF],
 [
+  m4_divert_text([DEFAULTS], [gl_roundf_required=plain])
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
   dnl Persuade glibc <math.h> to declare roundf().
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
@@ -50,6 +51,40 @@ int main()
     if test "$ROUNDF_LIBM" = missing; then
       REPLACE_ROUNDF=1
     fi
+    m4_ifdef([gl_FUNC_ROUNDF_IEEE], [
+      if test $gl_roundf_required = ieee && test $REPLACE_ROUNDF = 0; then
+        AC_CACHE_CHECK([whether roundf works according to ISO C 99 with IEC 60559],
+          [gl_cv_func_roundf_ieee],
+          [
+            save_LIBS="$LIBS"
+            LIBS="$LIBS $ROUNDF_LIBM"
+            AC_RUN_IFELSE(
+              [AC_LANG_SOURCE([[
+#ifndef __NO_MATH_INLINES
+# define __NO_MATH_INLINES 1 /* for glibc */
+#endif
+#include <math.h>
+]gl_FLOAT_MINUS_ZERO_CODE[
+]gl_FLOAT_SIGNBIT_CODE[
+int main()
+{
+  /* Test whether roundf (-0.0f) is -0.0f.  */
+  if (signbitf (minus_zerof) && !signbitf (roundf (minus_zerof)))
+    return 1;
+  return 0;
+}
+              ]])],
+              [gl_cv_func_roundf_ieee=yes],
+              [gl_cv_func_roundf_ieee=no],
+              [gl_cv_func_roundf_ieee="guessing no"])
+            LIBS="$save_LIBS"
+          ])
+        case "$gl_cv_func_roundf_ieee" in
+          *yes) ;;
+          *) REPLACE_ROUNDF=1 ;;
+        esac
+      fi
+    ])
   else
     HAVE_DECL_ROUNDF=0
   fi
diff --git a/modules/roundf-ieee b/modules/roundf-ieee
new file mode 100644 (file)
index 0000000..ffa2381
--- /dev/null
@@ -0,0 +1,27 @@
+Description:
+roundf() function according to ISO C 99 with IEC 60559.
+
+Files:
+m4/roundf-ieee.m4
+m4/minus-zero.m4
+m4/signbit.m4
+
+Depends-on:
+roundf
+
+configure.ac:
+gl_FUNC_ROUNDF_IEEE
+
+Makefile.am:
+
+Include:
+<math.h>
+
+Link:
+$(ROUNDF_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
diff --git a/modules/roundf-ieee-tests b/modules/roundf-ieee-tests
new file mode 100644 (file)
index 0000000..de231a5
--- /dev/null
@@ -0,0 +1,15 @@
+Files:
+tests/test-roundf-ieee.c
+tests/minus-zero.h
+tests/macros.h
+
+Depends-on:
+float
+signbit
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-roundf-ieee
+check_PROGRAMS += test-roundf-ieee
+test_roundf_ieee_LDADD = $(LDADD) @ROUNDF_LIBM@
index 2153ca1bcc9672868a0b012089db57c5d2fd6d6e..7ee4178f3efe7ef5f96ba7a180cc5da84aafbabc 100644 (file)
@@ -11,7 +11,6 @@ Depends-on:
 ceilf
 floorf
 isnanf-nolibm
-signbit
 stdbool
 stdint
 verify
diff --git a/tests/test-roundf-ieee.c b/tests/test-roundf-ieee.c
new file mode 100644 (file)
index 0000000..3948401
--- /dev/null
@@ -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 <config.h>
+
+#include <math.h>
+
+#include "minus-zero.h"
+#include "macros.h"
+
+int
+main ()
+{
+  /* Zero.  */
+  ASSERT (!signbit (roundf (0.0f)));
+  ASSERT (!!signbit (roundf (minus_zerof)) == !!signbit (minus_zerof));
+
+  return 0;
+}
index 354dcf02dc9538ce1a197bbf3f637edfefeb6d39..33609bb6bd8606b4e9870c8f26def680939ce6b9 100644 (file)
@@ -35,9 +35,7 @@ main ()
 {
   /* Zero.  */
   ASSERT (roundf (0.0f) == 0.0f);
-  ASSERT (!signbit (roundf (0.0f)));
   ASSERT (roundf (minus_zerof) == 0.0f);
-  ASSERT (!!signbit (minus_zerof) == !!signbit (roundf (minus_zerof)));
   /* Positive numbers.  */
   ASSERT (roundf (0.3f) == 0.0f);
   ASSERT (roundf (0.5f) == 1.0f);