changeset 15838:0e07b354626a

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.
author Bruno Haible <bruno@clisp.org>
date Thu, 06 Oct 2011 02:49:14 +0200
parents dd898709f077
children bb3ef01b637c
files ChangeLog doc/posix-functions/modff.texi lib/math.in.h lib/modff.c m4/math_h.m4 m4/modff.m4 modules/math modules/modff tests/test-math-c++.cc
diffstat 9 files changed, 128 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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.
 
--- a/doc/posix-functions/modff.texi
+++ b/doc/posix-functions/modff.texi
@@ -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
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -453,6 +453,22 @@
 #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)
new file mode 100644
--- /dev/null
+++ b/lib/modff.c
@@ -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;
+}
--- a/m4/math_h.m4
+++ b/m4/math_h.m4
@@ -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 @@
   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 @@
   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 @@
   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])
new file mode 100644
--- /dev/null
+++ b/m4/modff.m4
@@ -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])
+])
--- a/modules/math
+++ b/modules/math
@@ -52,6 +52,7 @@
 	      -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 @@
 	      -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' \
new file mode 100644
--- /dev/null
+++ b/modules/modff
@@ -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
--- a/tests/test-math-c++.cc
+++ b/tests/test-math-c++.cc
@@ -56,6 +56,9 @@
 //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));