New module 'truncf-ieee'.
authorBruno Haible <bruno@clisp.org>
Tue, 21 Dec 2010 14:44:21 +0000 (15:44 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 21 Dec 2010 16:30:27 +0000 (17:30 +0100)
* modules/truncf-ieee: New file.
* m4/truncf.m4 (gl_FUNC_TRUNCF): If gl_FUNC_TRUNCF_IEEE is also used,
test whether truncf works according to ISO C 99 with IEC 60559.
* m4/truncf-ieee.m4: New file.
* lib/math.in.h (truncf): Replace if REPLACE_TRUNCF is set.
* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_TRUNCF.
* modules/math (Makefile.am): Substitute REPLACE_TRUNCF.
* modules/truncf-ieee-tests: New file.
* tests/test-truncf-ieee.c: New file, based on tests/test-truncf1.c.
* tests/test-truncf1.c (main): Remove signbit tests.
* modules/truncf-tests (Depends-on): Remove 'signbit'.
* doc/posix-functions/truncf.texi: Mention the new module.

12 files changed:
ChangeLog
doc/posix-functions/truncf.texi
lib/math.in.h
m4/math_h.m4
m4/truncf-ieee.m4 [new file with mode: 0644]
m4/truncf.m4
modules/math
modules/truncf-ieee [new file with mode: 0644]
modules/truncf-ieee-tests [new file with mode: 0644]
modules/truncf-tests
tests/test-truncf-ieee.c [new file with mode: 0644]
tests/test-truncf1.c

index 9ad8d220e1c6ea02c4a1dcbc992e90c44e59555e..b7331717c7813a010b6f30a8916aaccf6cf858c2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2010-12-21  Bruno Haible  <bruno@clisp.org>
+
+       New module 'truncf-ieee'.
+       * modules/truncf-ieee: New file.
+       * m4/truncf.m4 (gl_FUNC_TRUNCF): If gl_FUNC_TRUNCF_IEEE is also used,
+       test whether truncf works according to ISO C 99 with IEC 60559.
+       * m4/truncf-ieee.m4: New file.
+       * lib/math.in.h (truncf): Replace if REPLACE_TRUNCF is set.
+       * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_TRUNCF.
+       * modules/math (Makefile.am): Substitute REPLACE_TRUNCF.
+       * modules/truncf-ieee-tests: New file.
+       * tests/test-truncf-ieee.c: New file, based on tests/test-truncf1.c.
+       * tests/test-truncf1.c (main): Remove signbit tests.
+       * modules/truncf-tests (Depends-on): Remove 'signbit'.
+       * doc/posix-functions/truncf.texi: Mention the new module.
+
 2010-12-21  Bruno Haible  <bruno@clisp.org>
 
        New module 'ceilf-ieee'.
 2010-12-21  Bruno Haible  <bruno@clisp.org>
 
        New module 'ceilf-ieee'.
index d6638b6e26e0f4078209c01ca9acb4a4642efb40..30e7e737c718471afd952206a8532aaabf9dac74 100644 (file)
@@ -4,9 +4,9 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/truncf.html}
 
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/truncf.html}
 
-Gnulib module: truncf
+Gnulib module: truncf or truncf-ieee
 
 
-Portability problems fixed by Gnulib:
+Portability problems fixed by either Gnulib module @code{truncf} or @code{truncf-ieee}:
 @itemize
 @item
 This function is missing on some platforms:
 @itemize
 @item
 This function is missing on some platforms:
@@ -16,6 +16,14 @@ This function is not declared (without @code{-D_GNU_SOURCE}) on some platforms:
 glibc 2.8.
 @end itemize
 
 glibc 2.8.
 @end itemize
 
+Portability problems fixed by Gnulib module @code{truncf-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
 Portability problems not fixed by Gnulib:
 @itemize
 @end itemize
index e05048aa8af63822a8d2aae64a16f6ea543092d6..fe2830b9c8ddf3fc2b73fbc106167443f6ad1609 100644 (file)
@@ -493,10 +493,18 @@ _GL_WARN_ON_USE (tanl, "tanl is unportable - "
 
 
 #if @GNULIB_TRUNCF@
 
 
 #if @GNULIB_TRUNCF@
-# if !@HAVE_DECL_TRUNCF@
+# if @REPLACE_TRUNCF@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define truncf rpl_truncf
+#  endif
+_GL_FUNCDECL_RPL (truncf, float, (float x));
+_GL_CXXALIAS_RPL (truncf, float, (float x));
+# else
+#  if !@HAVE_DECL_TRUNCF@
 _GL_FUNCDECL_SYS (truncf, float, (float x));
 _GL_FUNCDECL_SYS (truncf, float, (float x));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (truncf, float, (float x));
 _GL_CXXALIAS_SYS (truncf, float, (float x));
+# endif
 _GL_CXXALIASWARN (truncf);
 #elif defined GNULIB_POSIXCHECK
 # undef truncf
 _GL_CXXALIASWARN (truncf);
 #elif defined GNULIB_POSIXCHECK
 # undef truncf
index 2d89ca3f3ac2159501484d9d9badb83fb1252d09..0cca37e7662eef134f5b51b180275c5f9cb79fc1 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 21
+# math_h.m4 serial 22
 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,
 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,
@@ -136,5 +136,6 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_ROUNDL=0;            AC_SUBST([REPLACE_ROUNDL])
   REPLACE_SIGNBIT=0;           AC_SUBST([REPLACE_SIGNBIT])
   REPLACE_SIGNBIT_USING_GCC=0; AC_SUBST([REPLACE_SIGNBIT_USING_GCC])
   REPLACE_ROUNDL=0;            AC_SUBST([REPLACE_ROUNDL])
   REPLACE_SIGNBIT=0;           AC_SUBST([REPLACE_SIGNBIT])
   REPLACE_SIGNBIT_USING_GCC=0; AC_SUBST([REPLACE_SIGNBIT_USING_GCC])
+  REPLACE_TRUNCF=0;            AC_SUBST([REPLACE_TRUNCF])
   REPLACE_TRUNCL=0;            AC_SUBST([REPLACE_TRUNCL])
 ])
   REPLACE_TRUNCL=0;            AC_SUBST([REPLACE_TRUNCL])
 ])
diff --git a/m4/truncf-ieee.m4 b/m4/truncf-ieee.m4
new file mode 100644 (file)
index 0000000..7d91886
--- /dev/null
@@ -0,0 +1,15 @@
+# truncf-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 truncf.m4 and not inlined in the
+dnl module description), so that gl_FUNC_TRUNCF can test whether 'aclocal' has
+dnl found uses of this macro.
+
+AC_DEFUN([gl_FUNC_TRUNCF_IEEE],
+[
+  m4_divert_text([INIT_PREPARE], [gl_truncf_required=ieee])
+  AC_REQUIRE([gl_FUNC_TRUNCF])
+])
index 0b7c49ab2facf462a37bca85d74f47bbfa89769f..b92ffc1d4c38af541d78b3fda43d7a0b5dbc474c 100644 (file)
@@ -1,4 +1,4 @@
-# truncf.m4 serial 3
+# truncf.m4 serial 4
 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,
 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_TRUNCF],
 [
 
 AC_DEFUN([gl_FUNC_TRUNCF],
 [
+  m4_divert_text([DEFAULTS], [gl_truncf_required=plain])
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
   dnl Persuade glibc <math.h> to declare truncf().
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
   dnl Persuade glibc <math.h> to declare truncf().
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
@@ -40,8 +41,44 @@ AC_DEFUN([gl_FUNC_TRUNCF],
     if test "$TRUNCF_LIBM" = "?"; then
       TRUNCF_LIBM=
     fi
     if test "$TRUNCF_LIBM" = "?"; then
       TRUNCF_LIBM=
     fi
+    m4_ifdef([gl_FUNC_TRUNCF_IEEE], [
+      if test $gl_truncf_required = ieee && test $REPLACE_TRUNCF = 0; then
+        AC_CACHE_CHECK([whether truncf works according to ISO C 99 with IEC 60559],
+          [gl_cv_func_truncf_ieee],
+          [
+            save_LIBS="$LIBS"
+            LIBS="$LIBS $TRUNCF_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 truncf (-0.0f) is -0.0f.  */
+  if (signbitf (minus_zerof) && !signbitf (truncf (minus_zerof)))
+    return 1;
+  return 0;
+}
+              ]])],
+              [gl_cv_func_truncf_ieee=yes],
+              [gl_cv_func_truncf_ieee=no],
+              [gl_cv_func_truncf_ieee="guessing no"])
+            LIBS="$save_LIBS"
+          ])
+        case "$gl_cv_func_truncf_ieee" in
+          *yes) ;;
+          *) REPLACE_TRUNCF=1 ;;
+        esac
+      fi
+    ])
   else
     HAVE_DECL_TRUNCF=0
   else
     HAVE_DECL_TRUNCF=0
+  fi
+  if test $HAVE_DECL_TRUNCF = 0 || test $REPLACE_TRUNCF = 1; then
     AC_LIBOBJ([truncf])
     TRUNCF_LIBM=
   fi
     AC_LIBOBJ([truncf])
     TRUNCF_LIBM=
   fi
index ca9aa1ab3b6907af2bde3b40fef35a4a37b35e0e..6944646e1b5bdec31f39b2b153bd2aa24b419530 100644 (file)
@@ -107,6 +107,7 @@ math.h: math.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
              -e 's|@''REPLACE_ROUNDL''@|$(REPLACE_ROUNDL)|g' \
              -e 's|@''REPLACE_SIGNBIT''@|$(REPLACE_SIGNBIT)|g' \
              -e 's|@''REPLACE_SIGNBIT_USING_GCC''@|$(REPLACE_SIGNBIT_USING_GCC)|g' \
              -e 's|@''REPLACE_ROUNDL''@|$(REPLACE_ROUNDL)|g' \
              -e 's|@''REPLACE_SIGNBIT''@|$(REPLACE_SIGNBIT)|g' \
              -e 's|@''REPLACE_SIGNBIT_USING_GCC''@|$(REPLACE_SIGNBIT_USING_GCC)|g' \
+             -e 's|@''REPLACE_TRUNCF''@|$(REPLACE_TRUNCF)|g' \
              -e 's|@''REPLACE_TRUNCL''@|$(REPLACE_TRUNCL)|g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
              -e 's|@''REPLACE_TRUNCL''@|$(REPLACE_TRUNCL)|g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
diff --git a/modules/truncf-ieee b/modules/truncf-ieee
new file mode 100644 (file)
index 0000000..769c32f
--- /dev/null
@@ -0,0 +1,27 @@
+Description:
+truncf() function according to ISO C 99 with IEC 60559.
+
+Files:
+m4/truncf-ieee.m4
+m4/minus-zero.m4
+m4/signbit.m4
+
+Depends-on:
+truncf
+
+configure.ac:
+gl_FUNC_TRUNCF_IEEE
+
+Makefile.am:
+
+Include:
+<math.h>
+
+Link:
+$(TRUNCF_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
diff --git a/modules/truncf-ieee-tests b/modules/truncf-ieee-tests
new file mode 100644 (file)
index 0000000..0605d65
--- /dev/null
@@ -0,0 +1,15 @@
+Files:
+tests/test-truncf-ieee.c
+tests/minus-zero.h
+tests/macros.h
+
+Depends-on:
+float
+signbit
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-truncf-ieee
+check_PROGRAMS += test-truncf-ieee
+test_truncf_ieee_LDADD = $(LDADD) @TRUNCF_LIBM@
index e2961a16b05b09366ed9a19ff3a51c910f792bea..27b93f2a2a8b4bf4814a4d23b35f950b4031b5f2 100644 (file)
@@ -9,7 +9,6 @@ tests/macros.h
 Depends-on:
 float
 isnanf-nolibm
 Depends-on:
 float
 isnanf-nolibm
-signbit
 stdbool
 stdint
 
 stdbool
 stdint
 
diff --git a/tests/test-truncf-ieee.c b/tests/test-truncf-ieee.c
new file mode 100644 (file)
index 0000000..c5c779a
--- /dev/null
@@ -0,0 +1,32 @@
+/* Test of rounding towards 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 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <math.h>
+
+#include "minus-zero.h"
+#include "macros.h"
+
+int
+main ()
+{
+  /* Zero.  */
+  ASSERT (!signbit (truncf (0.0f)));
+  ASSERT (!!signbit (truncf (minus_zerof)) == !!signbit (minus_zerof));
+
+  return 0;
+}
index 6953c8bbcfbf3c4d840b1a0366d207e5637117da..b5f48dd6ae5b1cdb74c02a67eb9fe72c9c2c8d44 100644 (file)
@@ -33,9 +33,7 @@ main ()
 {
   /* Zero.  */
   ASSERT (truncf (0.0f) == 0.0f);
 {
   /* Zero.  */
   ASSERT (truncf (0.0f) == 0.0f);
-  ASSERT (!signbit (truncf (0.0f)));
   ASSERT (truncf (minus_zerof) == 0.0f);
   ASSERT (truncf (minus_zerof) == 0.0f);
-  ASSERT (!!signbit (minus_zerof) == !!signbit (truncf (minus_zerof)));
   /* Positive numbers.  */
   ASSERT (truncf (0.3f) == 0.0f);
   ASSERT (truncf (0.7f) == 0.0f);
   /* Positive numbers.  */
   ASSERT (truncf (0.3f) == 0.0f);
   ASSERT (truncf (0.7f) == 0.0f);