changeset 9287:ec7800681aff

New module 'truncl'.
author Bruno Haible <bruno@clisp.org>
date Fri, 05 Oct 2007 01:39:53 +0200
parents 8af2c249410b
children 6e111172a97d
files ChangeLog doc/functions/truncl.texi lib/math.in.h lib/truncl.c m4/math_h.m4 m4/truncl.m4 modules/math modules/truncl
diffstat 8 files changed, 134 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+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.
--- a/doc/functions/truncl.texi
+++ b/doc/functions/truncl.texi
@@ -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
-@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
+
+Portability problems not fixed by Gnulib:
+@itemize
+@end itemize
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -250,6 +250,19 @@
      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@
new file mode 100644
--- /dev/null
+++ b/lib/truncl.c
@@ -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"
--- a/m4/math_h.m4
+++ b/m4/math_h.m4
@@ -26,6 +26,7 @@
   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 @@
   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])
new file mode 100644
--- /dev/null
+++ b/m4/truncl.m4
@@ -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])
+])
--- a/modules/math
+++ b/modules/math
@@ -29,6 +29,7 @@
 	      -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 @@
 	      -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' \
new file mode 100644
--- /dev/null
+++ b/modules/truncl
@@ -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
+