New module 'modff'.
authorBruno Haible <bruno@clisp.org>
Thu, 6 Oct 2011 00:49:14 +0000 (02:49 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 6 Oct 2011 00:49:14 +0000 (02:49 +0200)
* lib/math.in.h (modff): New declaration.
* lib/modff.c: New file.
* m4/modff.m4: New file.
* m4/math_h.m4 (gl_MATH_H): Test whether modff is declared.
(gl_MATH_H_DEFAULTS): Initialize GNULIB_MODFF, HAVE_MODFF.
* modules/math (Makefile.am): Substitute GNULIB_MODFF, HAVE_MODFF.
* modules/modff: New file.
* tests/test-math-c++.cc: Check the declaration of modff.
* doc/posix-functions/modff.texi: Mention the new module.

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

index d384b8c..33af3dc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2011-10-05  Bruno Haible  <bruno@clisp.org>
 
+       New module 'modff'.
+       * lib/math.in.h (modff): New declaration.
+       * lib/modff.c: New file.
+       * m4/modff.m4: New file.
+       * m4/math_h.m4 (gl_MATH_H): Test whether modff is declared.
+       (gl_MATH_H_DEFAULTS): Initialize GNULIB_MODFF, HAVE_MODFF.
+       * modules/math (Makefile.am): Substitute GNULIB_MODFF, HAVE_MODFF.
+       * modules/modff: New file.
+       * tests/test-math-c++.cc: Check the declaration of modff.
+       * doc/posix-functions/modff.texi: Mention the new module.
+
        modf tests: Make test sharper.
        * tests/test-modf.c (main): Strengthen upper bound.
 
index af75967..f14cf5e 100644 (file)
@@ -4,18 +4,18 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/modff.html}
 
-Gnulib module: ---
+Gnulib module: modff
 
 Portability problems fixed by Gnulib:
 @itemize
-@end itemize
-
-Portability problems not fixed by Gnulib:
-@itemize
 @item
 This function is missing on some platforms:
 MacOS X 10.5, Minix 3.1.8, AIX 5.1, HP-UX 11.
 @item
-This function is only defined as a macro with arguments on some platforms:
+This function is only defined as a buggy macro with arguments on some platforms:
 MSVC 9.
 @end itemize
+
+Portability problems not fixed by Gnulib:
+@itemize
+@end itemize
index 110a1e6..435d79c 100644 (file)
@@ -453,6 +453,22 @@ _GL_WARN_ON_USE (logl, "logl is unportable - "
 #endif
 
 
+#if @GNULIB_MODFF@
+# if !@HAVE_MODFF@
+#  undef modff
+_GL_FUNCDECL_SYS (modff, float, (float x, float *iptr) _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (modff, float, (float x, float *iptr));
+_GL_CXXALIASWARN (modff);
+#elif defined GNULIB_POSIXCHECK
+# undef modff
+# if HAVE_RAW_DECL_MODFF
+_GL_WARN_ON_USE (modff, "modff is unportable - "
+                 "use gnulib module modff for portability");
+# endif
+#endif
+
+
 #if @GNULIB_ROUNDF@
 # if @REPLACE_ROUNDF@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
diff --git a/lib/modff.c b/lib/modff.c
new file mode 100644 (file)
index 0000000..1b2554c
--- /dev/null
@@ -0,0 +1,29 @@
+/* Get signed integer and fractional parts of a floating-point number.
+   Copyright (C) 2011 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>
+
+float
+modff (float x, float *iptr)
+{
+  double i;
+  double frac = modf ((double) x, &i);
+  *iptr = (float) i;
+  return (float) frac;
+}
index 4d4b443..e3b29fe 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 27
+# math_h.m4 serial 28
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -40,7 +40,8 @@ AC_DEFUN([gl_MATH_H],
   dnl corresponding gnulib module is not in use.
   gl_WARN_ON_USE_PREPARE([[#include <math.h>]],
     [acosl asinl atanl ceilf ceill cosl expl fabsf floorf floorl fmodf frexpl
-     ldexpl logb logl round roundf roundl sinl sqrtl tanl trunc truncf truncl])
+     ldexpl logb logl modff round roundf roundl sinl sqrtl
+     tanl trunc truncf truncl])
 ])
 
 AC_DEFUN([gl_MATH_MODULE_INDICATOR],
@@ -78,6 +79,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   GNULIB_LDEXPL=0;   AC_SUBST([GNULIB_LDEXPL])
   GNULIB_LOGB=0;     AC_SUBST([GNULIB_LOGB])
   GNULIB_LOGL=0;     AC_SUBST([GNULIB_LOGL])
+  GNULIB_MODFF=0;    AC_SUBST([GNULIB_MODFF])
   GNULIB_ROUND=0;    AC_SUBST([GNULIB_ROUND])
   GNULIB_ROUNDF=0;   AC_SUBST([GNULIB_ROUNDF])
   GNULIB_ROUNDL=0;   AC_SUBST([GNULIB_ROUNDL])
@@ -100,6 +102,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   HAVE_ISNAND=1;               AC_SUBST([HAVE_ISNAND])
   HAVE_ISNANL=1;               AC_SUBST([HAVE_ISNANL])
   HAVE_LOGL=1;                 AC_SUBST([HAVE_LOGL])
+  HAVE_MODFF=1;                AC_SUBST([HAVE_MODFF])
   HAVE_SINL=1;                 AC_SUBST([HAVE_SINL])
   HAVE_SQRTL=1;                AC_SUBST([HAVE_SQRTL])
   HAVE_TANL=1;                 AC_SUBST([HAVE_TANL])
diff --git a/m4/modff.m4 b/m4/modff.m4
new file mode 100644 (file)
index 0000000..181c406
--- /dev/null
@@ -0,0 +1,25 @@
+# modff.m4 serial 1
+dnl Copyright (C) 2011 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_MODFF],
+[
+  AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  AC_REQUIRE([gl_FUNC_MODF])
+
+  dnl Test whether modff() exists. Assume that modff(), if it exists, is
+  dnl defined in the same library as modf().
+  save_LIBS="$LIBS"
+  LIBS="$LIBS $MODF_LIBM"
+  AC_CHECK_FUNCS([modff])
+  LIBS="$save_LIBS"
+  if test $ac_cv_func_modff = yes; then
+    MODFF_LIBM="$MODF_LIBM"
+  else
+    HAVE_MODFF=0
+    MODFF_LIBM="$MODF_LIBM"
+  fi
+  AC_SUBST([MODFF_LIBM])
+])
index 6875218..b40edb1 100644 (file)
@@ -52,6 +52,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's/@''GNULIB_LDEXPL''@/$(GNULIB_LDEXPL)/g' \
              -e 's/@''GNULIB_LOGB''@/$(GNULIB_LOGB)/g' \
              -e 's/@''GNULIB_LOGL''@/$(GNULIB_LOGL)/g' \
+             -e 's/@''GNULIB_MODFF''@/$(GNULIB_MODFF)/g' \
              -e 's/@''GNULIB_ROUND''@/$(GNULIB_ROUND)/g' \
              -e 's/@''GNULIB_ROUNDF''@/$(GNULIB_ROUNDF)/g' \
              -e 's/@''GNULIB_ROUNDL''@/$(GNULIB_ROUNDL)/g' \
@@ -74,6 +75,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''HAVE_ISNAND''@|$(HAVE_ISNAND)|g' \
              -e 's|@''HAVE_ISNANL''@|$(HAVE_ISNANL)|g' \
              -e 's|@''HAVE_LOGL''@|$(HAVE_LOGL)|g' \
+             -e 's|@''HAVE_MODFF''@|$(HAVE_MODFF)|g' \
              -e 's|@''HAVE_SINL''@|$(HAVE_SINL)|g' \
              -e 's|@''HAVE_SQRTL''@|$(HAVE_SQRTL)|g' \
              -e 's|@''HAVE_TANL''@|$(HAVE_TANL)|g' \
diff --git a/modules/modff b/modules/modff
new file mode 100644 (file)
index 0000000..891b01c
--- /dev/null
@@ -0,0 +1,31 @@
+Description:
+modff() function: get signed integer and fractional parts.
+
+Files:
+lib/modff.c
+m4/modff.m4
+
+Depends-on:
+math
+modf            [test $HAVE_MODFF = 0]
+
+configure.ac:
+gl_FUNC_MODFF
+if test $HAVE_MODFF = 0; then
+  AC_LIBOBJ([modff])
+fi
+gl_MATH_MODULE_INDICATOR([modff])
+
+Makefile.am:
+
+Include:
+<math.h>
+
+Link:
+$(MODFF_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
index b6141e1..1782a25 100644 (file)
@@ -56,6 +56,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::frexp, double, (double, int *));
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::log1p, double, (double));
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::logb, double, (double));
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::log, double, (double));
+#if GNULIB_TEST_MODFF
+SIGNATURE_CHECK (GNULIB_NAMESPACE::modff, float, (float, float *));
+#endif
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::modf, double, (double, double *));
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::nextafter, double, (double, double));
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::pow, double, (double, double));