New module 'truncl'.
authorBruno Haible <bruno@clisp.org>
Thu, 4 Oct 2007 23:39:53 +0000 (01:39 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 4 Oct 2007 23:39:53 +0000 (01:39 +0200)
ChangeLog
doc/functions/truncl.texi
lib/math.in.h
lib/truncl.c [new file with mode: 0644]
m4/math_h.m4
m4/truncl.m4 [new file with mode: 0644]
modules/math
modules/truncl [new file with mode: 0644]

index f2b3dfc..fae1df6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2007-10-04  Bruno Haible  <bruno@clisp.org>
 
+       * modules/truncl: New file.
+       * lib/truncl.c: New file.
+       * m4/truncl.m4: New file.
+       * lib/math.in.h (truncl): New declaration.
+       * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize GNULIB_TRUNCL and
+       HAVE_DECL_TRUNCL.
+       * modules/math (Makefile.am): Substitute also GNULIB_TRUNCL and
+       HAVE_DECL_TRUNCL.
+       * doc/functions/truncl.texi: Mention the 'truncl' module.
+
+2007-10-04  Bruno Haible  <bruno@clisp.org>
+
        * modules/truncf-tests: New file.
        * tests/test-truncf.c: New file.
 
index 43ed254..5e402ec 100644 (file)
@@ -4,15 +4,15 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/truncl.html}
 
-Gnulib module: ---
+Gnulib module: truncl
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+FreeBSD 5.2.1, NetBSD 3.0, OpenBSD 3.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, Interix 3.5, BeOS.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-FreeBSD 5.2.1, NetBSD 3.0, OpenBSD 3.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, Interix 3.5, BeOS.
 @end itemize
index 3febfe5..fb70011 100644 (file)
@@ -250,6 +250,19 @@ extern double trunc (double x);
      trunc (x))
 #endif
 
+#if @GNULIB_TRUNCL@
+# if !@HAVE_DECL_TRUNCL@
+#  define truncl rpl_truncl
+extern long double truncl (long double x);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef truncl
+# define truncl(x) \
+    (GL_LINK_WARNING ("truncl is unportable - " \
+                      "use gnulib module truncl for portability"), \
+     truncl (x))
+#endif
+
 
 #if @GNULIB_SIGNBIT@
 # if @REPLACE_SIGNBIT@
diff --git a/lib/truncl.c b/lib/truncl.c
new file mode 100644 (file)
index 0000000..a3117af
--- /dev/null
@@ -0,0 +1,21 @@
+/* Round towards zero.
+   Copyright (C) 2007 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 2, 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.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
+
+#define USE_LONG_DOUBLE
+#include "trunc.c"
index 1380492..d9a8cc4 100644 (file)
@@ -26,6 +26,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   GNULIB_SIGNBIT=0; AC_SUBST([GNULIB_SIGNBIT])
   GNULIB_TRUNC=0;   AC_SUBST([GNULIB_TRUNC])
   GNULIB_TRUNCF=0;  AC_SUBST([GNULIB_TRUNCF])
+  GNULIB_TRUNCL=0;  AC_SUBST([GNULIB_TRUNCL])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_DECL_ACOSL=1;  AC_SUBST([HAVE_DECL_ACOSL])
   HAVE_DECL_ASINL=1;  AC_SUBST([HAVE_DECL_ASINL])
@@ -42,6 +43,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   HAVE_DECL_TANL=1;   AC_SUBST([HAVE_DECL_TANL])
   HAVE_DECL_TRUNC=1;  AC_SUBST([HAVE_DECL_TRUNC])
   HAVE_DECL_TRUNCF=1; AC_SUBST([HAVE_DECL_TRUNCF])
+  HAVE_DECL_TRUNCL=1; AC_SUBST([HAVE_DECL_TRUNCL])
   REPLACE_FREXP=0;    AC_SUBST([REPLACE_FREXP])
   REPLACE_FREXPL=0;   AC_SUBST([REPLACE_FREXPL])
   REPLACE_LDEXPL=0;   AC_SUBST([REPLACE_LDEXPL])
diff --git a/m4/truncl.m4 b/m4/truncl.m4
new file mode 100644 (file)
index 0000000..aabd27f
--- /dev/null
@@ -0,0 +1,48 @@
+# truncl.m4 serial 1
+dnl Copyright (C) 2007 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.
+
+AC_DEFUN([gl_FUNC_TRUNCL],
+[
+  AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  dnl Persuade glibc <math.h> to declare truncl().
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+  dnl Test whether truncl() is declared.
+  AC_CHECK_DECLS([truncl], , , [#include <math.h>])
+  if test "$ac_cv_have_decl_truncl" = yes; then
+    dnl Test whether truncl() can be used without libm.
+    TRUNCL_LIBM=?
+    AC_TRY_LINK([
+       #ifndef __NO_MATH_INLINES
+       # define __NO_MATH_INLINES 1 /* for glibc */
+       #endif
+       #include <math.h>
+       long double x;],
+      [x = truncl(x);],
+      [TRUNCL_LIBM=])
+    if test "$TRUNCL_LIBM" = "?"; then
+      save_LIBS="$LIBS"
+      LIBS="$LIBS -lm"
+      AC_TRY_LINK([
+         #ifndef __NO_MATH_INLINES
+         # define __NO_MATH_INLINES 1 /* for glibc */
+         #endif
+         #include <math.h>
+         long double x;],
+        [x = truncl(x);],
+        [TRUNCL_LIBM="-lm"])
+      LIBS="$save_LIBS"
+    fi
+    if test "$TRUNCL_LIBM" = "?"; then
+      TRUNCL_LIBM=
+    fi
+  else
+    HAVE_DECL_TRUNCL=0
+    AC_LIBOBJ([truncl])
+    TRUNCL_LIBM=
+  fi
+  AC_SUBST([HAVE_DECL_TRUNCL])
+  AC_SUBST([TRUNCL_LIBM])
+])
index aa801aa..db0faee 100644 (file)
@@ -29,6 +29,7 @@ math.h: math.in.h
              -e 's|@''GNULIB_SIGNBIT''@|$(GNULIB_SIGNBIT)|g' \
              -e 's|@''GNULIB_TRUNC''@|$(GNULIB_TRUNC)|g' \
              -e 's|@''GNULIB_TRUNCF''@|$(GNULIB_TRUNCF)|g' \
+             -e 's|@''GNULIB_TRUNCL''@|$(GNULIB_TRUNCL)|g' \
              -e 's|@''HAVE_DECL_ACOSL''@|$(HAVE_DECL_ACOSL)|g' \
              -e 's|@''HAVE_DECL_ASINL''@|$(HAVE_DECL_ASINL)|g' \
              -e 's|@''HAVE_DECL_ATANL''@|$(HAVE_DECL_ATANL)|g' \
@@ -44,6 +45,7 @@ math.h: math.in.h
              -e 's|@''HAVE_DECL_TANL''@|$(HAVE_DECL_TANL)|g' \
              -e 's|@''HAVE_DECL_TRUNC''@|$(HAVE_DECL_TRUNC)|g' \
              -e 's|@''HAVE_DECL_TRUNCF''@|$(HAVE_DECL_TRUNCF)|g' \
+             -e 's|@''HAVE_DECL_TRUNCL''@|$(HAVE_DECL_TRUNCL)|g' \
              -e 's|@''REPLACE_FREXP''@|$(REPLACE_FREXP)|g' \
              -e 's|@''REPLACE_FREXPL''@|$(REPLACE_FREXPL)|g' \
              -e 's|@''REPLACE_LDEXPL''@|$(REPLACE_LDEXPL)|g' \
diff --git a/modules/truncl b/modules/truncl
new file mode 100644 (file)
index 0000000..d3d8884
--- /dev/null
@@ -0,0 +1,31 @@
+Description:
+truncl() function: round towards zero.
+
+Files:
+lib/truncl.c
+lib/trunc.c
+m4/truncl.m4
+
+Depends-on:
+math
+extensions
+float
+
+configure.ac:
+gl_FUNC_TRUNCL
+gl_MATH_MODULE_INDICATOR([truncl])
+
+Makefile.am:
+
+Include:
+<math.h>
+
+Link:
+$(TRUNCL_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+