New module 'modfl'.
authorBruno Haible <bruno@clisp.org>
Sat, 25 Feb 2012 14:30:53 +0000 (15:30 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 25 Feb 2012 14:30:53 +0000 (15:30 +0100)
* lib/math.in.h (modfl): New declaration.
* lib/modfl.c: New file.
* m4/modfl.m4: New file.
* m4/math_h.m4 (gl_MATH_H): Test whether modfl is declared.
(gl_MATH_H_DEFAULTS): Initialize GNULIB_MODFL, HAVE_MODFL.
* modules/math (Makefile.am): Substitute GNULIB_MODFL, HAVE_MODFL.
* modules/modfl: New file.
* doc/posix-functions/modfl.texi: Mention the new module.

ChangeLog
doc/posix-functions/modfl.texi
lib/math.in.h
lib/modfl.c [new file with mode: 0644]
m4/math_h.m4
m4/modfl.m4 [new file with mode: 0644]
modules/math
modules/modfl [new file with mode: 0644]

index 3a0396a..3c21033 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2012-02-25  Bruno Haible  <bruno@clisp.org>
 
+       New module 'modfl'.
+       * lib/math.in.h (modfl): New declaration.
+       * lib/modfl.c: New file.
+       * m4/modfl.m4: New file.
+       * m4/math_h.m4 (gl_MATH_H): Test whether modfl is declared.
+       (gl_MATH_H_DEFAULTS): Initialize GNULIB_MODFL, HAVE_MODFL.
+       * modules/math (Makefile.am): Substitute GNULIB_MODFL, HAVE_MODFL.
+       * modules/modfl: New file.
+       * doc/posix-functions/modfl.texi: Mention the new module.
+
+2012-02-25  Bruno Haible  <bruno@clisp.org>
+
        Tests for module 'fabsl'.
        * modules/fabsl-tests: New file.
        * tests/test-fabsl.c: New file.
index 7693503..cb16466 100644 (file)
@@ -4,14 +4,10 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/modfl.html}
 
-Gnulib module: ---
+Gnulib module: modfl
 
 Portability problems fixed by Gnulib:
 @itemize
-@end itemize
-
-Portability problems not fixed by Gnulib:
-@itemize
 @item
 This function is missing on some platforms:
 FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, Interix 3.5.
@@ -19,3 +15,7 @@ FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11, IRIX 6.5, Solaris 9
 This function is only defined as a macro with arguments on some platforms:
 MSVC 9.
 @end itemize
+
+Portability problems not fixed by Gnulib:
+@itemize
+@end itemize
index d7b0e3d..aeb25d0 100644 (file)
@@ -841,6 +841,22 @@ _GL_WARN_ON_USE (modff, "modff is unportable - "
 # endif
 #endif
 
+#if @GNULIB_MODFL@
+# if !@HAVE_MODFL@
+#  undef modfl
+_GL_FUNCDECL_SYS (modfl, long double, (long double x, long double *iptr)
+                                      _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (modfl, long double, (long double x, long double *iptr));
+_GL_CXXALIASWARN (modfl);
+#elif defined GNULIB_POSIXCHECK
+# undef modfl
+# if HAVE_RAW_DECL_MODFL
+_GL_WARN_ON_USE (modfl, "modfl is unportable - "
+                 "use gnulib module modfl for portability");
+# endif
+#endif
+
 
 #if @GNULIB_POWF@
 # if !@HAVE_POWF@
diff --git a/lib/modfl.c b/lib/modfl.c
new file mode 100644 (file)
index 0000000..770294b
--- /dev/null
@@ -0,0 +1,43 @@
+/* Get signed integer and fractional parts of a floating-point number.
+   Copyright (C) 2012 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>
+
+/* Specification.  */
+#include <math.h>
+
+#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+
+long double
+modfl (long double x, long double *iptr)
+{
+  double integer_part;
+  double fractional_part = modf (x, &integer_part);
+  *iptr = integer_part;
+  return fractional_part;
+}
+
+#else
+
+long double
+modfl (long double x, long double *iptr)
+{
+  long double integer_part = truncl (x);
+  *iptr = integer_part;
+  return x - integer_part;
+}
+
+#endif
index 2dad999..cdb1b75 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 57
+# math_h.m4 serial 58
 dnl Copyright (C) 2007-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -42,7 +42,7 @@ AC_DEFUN([gl_MATH_H],
     [acosf acosl asinf asinl atanf atanl
      ceilf ceill copysign copysignf copysignl cosf cosl coshf
      expf expl fabsf fabsl floorf floorl fma fmaf fmal fmodf frexpf frexpl
-     ldexpf ldexpl logb logf logl log10f modff powf
+     ldexpf ldexpl logb logf logl log10f modff modfl powf
      rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl
      tanf tanl tanhf trunc truncf truncl])
 ])
@@ -101,6 +101,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   GNULIB_LOGL=0;      AC_SUBST([GNULIB_LOGL])
   GNULIB_LOG10F=0;    AC_SUBST([GNULIB_LOG10F])
   GNULIB_MODFF=0;     AC_SUBST([GNULIB_MODFF])
+  GNULIB_MODFL=0;     AC_SUBST([GNULIB_MODFL])
   GNULIB_POWF=0;      AC_SUBST([GNULIB_POWF])
   GNULIB_RINT=0;      AC_SUBST([GNULIB_RINT])
   GNULIB_RINTF=0;     AC_SUBST([GNULIB_RINTF])
@@ -151,6 +152,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   HAVE_LOGL=1;                 AC_SUBST([HAVE_LOGL])
   HAVE_LOG10F=1;               AC_SUBST([HAVE_LOG10F])
   HAVE_MODFF=1;                AC_SUBST([HAVE_MODFF])
+  HAVE_MODFL=1;                AC_SUBST([HAVE_MODFL])
   HAVE_POWF=1;                 AC_SUBST([HAVE_POWF])
   HAVE_RINT=1;                 AC_SUBST([HAVE_RINT])
   HAVE_RINTF=1;                AC_SUBST([HAVE_RINTF])
diff --git a/m4/modfl.m4 b/m4/modfl.m4
new file mode 100644 (file)
index 0000000..98aa363
--- /dev/null
@@ -0,0 +1,28 @@
+# modfl.m4 serial 1
+dnl Copyright (C) 2011-2012 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_MODFL],
+[
+  AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
+
+  dnl Test whether modfl() exists. We cannot assume that modfl(), if it
+  dnl exists, is defined in the same library as modf(). This is not the case
+  dnl on FreeBSD, Solaris.
+  gl_MATHFUNC([modfl], [long double], [(long double, long double *)])
+  if test $gl_cv_func_modfl_no_libm = no \
+     && test $gl_cv_func_modfl_in_libm = no; then
+    HAVE_MODFL=0
+    if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
+      AC_REQUIRE([gl_FUNC_MODF])
+      MODFL_LIBM="$MODF_LIBM"
+    else
+      AC_REQUIRE([gl_FUNC_TRUNCL])
+      MODFL_LIBM="$TRUNCL_LIBM"
+    fi
+  fi
+  AC_SUBST([MODFL_LIBM])
+])
index d450afa..ac8760d 100644 (file)
@@ -71,6 +71,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's/@''GNULIB_LOGL''@/$(GNULIB_LOGL)/g' \
              -e 's/@''GNULIB_LOG10F''@/$(GNULIB_LOG10F)/g' \
              -e 's/@''GNULIB_MODFF''@/$(GNULIB_MODFF)/g' \
+             -e 's/@''GNULIB_MODFL''@/$(GNULIB_MODFL)/g' \
              -e 's/@''GNULIB_POWF''@/$(GNULIB_POWF)/g' \
              -e 's/@''GNULIB_RINT''@/$(GNULIB_RINT)/g' \
              -e 's/@''GNULIB_RINTF''@/$(GNULIB_RINTF)/g' \
@@ -121,6 +122,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''HAVE_LOGL''@|$(HAVE_LOGL)|g' \
              -e 's|@''HAVE_LOG10F''@|$(HAVE_LOG10F)|g' \
              -e 's|@''HAVE_MODFF''@|$(HAVE_MODFF)|g' \
+             -e 's|@''HAVE_MODFL''@|$(HAVE_MODFL)|g' \
              -e 's|@''HAVE_POWF''@|$(HAVE_POWF)|g' \
              -e 's|@''HAVE_RINT''@|$(HAVE_RINT)|g' \
              -e 's|@''HAVE_RINTF''@|$(HAVE_RINTF)|g' \
diff --git a/modules/modfl b/modules/modfl
new file mode 100644 (file)
index 0000000..0c6f53b
--- /dev/null
@@ -0,0 +1,33 @@
+Description:
+modfl() function: get signed integer and fractional parts.
+
+Files:
+lib/modfl.c
+m4/modfl.m4
+m4/mathfunc.m4
+
+Depends-on:
+math
+modf            [test $HAVE_MODFL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
+truncl          [test $HAVE_MODFL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+
+configure.ac:
+gl_FUNC_MODFL
+if test $HAVE_MODFL = 0; then
+  AC_LIBOBJ([modfl])
+fi
+gl_MATH_MODULE_INDICATOR([modfl])
+
+Makefile.am:
+
+Include:
+<math.h>
+
+Link:
+$(MODFL_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible