New module 'fmodl'.
authorBruno Haible <bruno@clisp.org>
Sat, 25 Feb 2012 16:24:31 +0000 (17:24 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 25 Feb 2012 16:24:31 +0000 (17:24 +0100)
* lib/math.in.h (fmodl): New declaration.
* lib/fmodl.c: New file.
* m4/fmodl.m4: New file.
* m4/math_h.m4 (gl_MATH_H): Test whether fmodl is declared.
(gl_MATH_H_DEFAULTS): Initialize GNULIB_FMODL, HAVE_FMODL,
REPLACE_FMODL.
* modules/math (Makefile.am): Substitute GNULIB_FMODL, HAVE_FMODL,
REPLACE_FMODL.
* modules/fmodl: New file.
* doc/posix-functions/fmodl.texi: Mention the new module.

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

index 641e872..dda5fbc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2012-02-25  Bruno Haible  <bruno@clisp.org>
 
+       New module 'fmodl'.
+       * lib/math.in.h (fmodl): New declaration.
+       * lib/fmodl.c: New file.
+       * m4/fmodl.m4: New file.
+       * m4/math_h.m4 (gl_MATH_H): Test whether fmodl is declared.
+       (gl_MATH_H_DEFAULTS): Initialize GNULIB_FMODL, HAVE_FMODL,
+       REPLACE_FMODL.
+       * modules/math (Makefile.am): Substitute GNULIB_FMODL, HAVE_FMODL,
+       REPLACE_FMODL.
+       * modules/fmodl: New file.
+       * doc/posix-functions/fmodl.texi: Mention the new module.
+
+2012-02-25  Bruno Haible  <bruno@clisp.org>
+
        Tests for module 'modfl'.
        * modules/modfl-tests: New file.
        * tests/test-modfl.c: New file.
index 9ce8b5d..7dc3627 100644 (file)
@@ -4,18 +4,21 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/fmodl.html}
 
-Gnulib module: ---
+Gnulib module: fmodl
 
 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, BeOS.
 @item
 This function is only defined as a macro with arguments on some platforms:
 MSVC 9.
+@item
+This function is not declared and does not work on some platforms:
+AIX 5.1.
+@end itemize
+
+Portability problems not fixed by Gnulib:
+@itemize
 @end itemize
diff --git a/lib/fmodl.c b/lib/fmodl.c
new file mode 100644 (file)
index 0000000..0c2542f
--- /dev/null
@@ -0,0 +1,39 @@
+/* Remainder.
+   Copyright (C) 2011-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
+fmodl (long double x, long double y)
+{
+  return fmod (x, y);
+}
+
+#else
+
+long double
+fmodl (long double x, long double y)
+{
+  long double i = truncl (x / y);
+  return fmal (- i, y, x);
+}
+
+#endif
index aeb25d0..87e4258 100644 (file)
@@ -629,6 +629,30 @@ _GL_WARN_ON_USE (fmodf, "fmodf is unportable - "
 # endif
 #endif
 
+#if @GNULIB_FMODL@
+# if @REPLACE_FMODL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fmodl
+#   define fmodl rpl_fmodl
+#  endif
+_GL_FUNCDECL_RPL (fmodl, long double, (long double x, long double y));
+_GL_CXXALIAS_RPL (fmodl, long double, (long double x, long double y));
+# else
+#  if !@HAVE_FMODL@
+#   undef fmodl
+_GL_FUNCDECL_SYS (fmodl, long double, (long double x, long double y));
+#  endif
+_GL_CXXALIAS_SYS (fmodl, long double, (long double x, long double y));
+# endif
+_GL_CXXALIASWARN (fmodl);
+#elif defined GNULIB_POSIXCHECK
+# undef fmodl
+# if HAVE_RAW_DECL_FMODL
+_GL_WARN_ON_USE (fmodl, "fmodl is unportable - "
+                 "use gnulib module fmodl for portability");
+# endif
+#endif
+
 
 /* Write x as
      x = mantissa * 2^exp
diff --git a/m4/fmodl.m4 b/m4/fmodl.m4
new file mode 100644 (file)
index 0000000..3207215
--- /dev/null
@@ -0,0 +1,55 @@
+# fmodl.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_FMODL],
+[
+  AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
+  AC_REQUIRE([gl_FUNC_FMOD])
+
+  dnl Test whether fmodl() is declared.
+  dnl AIX 5.1 has fmodl() in libc but doesn't declare it in <math.h>, and the
+  dnl function produces NaN results for finite values.
+  AC_CHECK_DECL([fmodl],
+    [ac_cv_have_decl_fmodl=yes], [ac_cv_have_decl_fmodl=no],
+    [[#include <math.h>]])
+
+  dnl Test whether fmodl() exists. Assume that fmodl(), if it exists, is
+  dnl defined in the same library as fmod().
+  save_LIBS="$LIBS"
+  LIBS="$LIBS $FMOD_LIBM"
+  AC_CHECK_FUNCS([fmodl])
+  LIBS="$save_LIBS"
+  if test $ac_cv_func_fmodl = yes; then
+    if test $ac_cv_have_decl_fmodl = yes; then
+      FMODL_LIBM="$FMOD_LIBM"
+    else
+      REPLACE_FMODL=1
+    fi
+  else
+    HAVE_FMODL=0
+  fi
+  if test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; then
+    if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
+      FMODL_LIBM="$FMOD_LIBM"
+    else
+      AC_REQUIRE([gl_FUNC_TRUNCL])
+      AC_REQUIRE([gl_FUNC_FMAL])
+      FMODL_LIBM=
+      dnl Append $TRUNCL_LIBM to FMODL_LIBM, avoiding gratuitous duplicates.
+      case " $FMODL_LIBM " in
+        *" $TRUNCL_LIBM "*) ;;
+        *) FMODL_LIBM="$FMODL_LIBM $TRUNCL_LIBM" ;;
+      esac
+      dnl Append $FMAL_LIBM to FMODL_LIBM, avoiding gratuitous duplicates.
+      case " $FMODL_LIBM " in
+        *" $FMAL_LIBM "*) ;;
+        *) FMODL_LIBM="$FMODL_LIBM $FMAL_LIBM" ;;
+      esac
+    fi
+  fi
+  AC_SUBST([FMODL_LIBM])
+])
index cdb1b75..410cdde 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 58
+# math_h.m4 serial 59
 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,
@@ -41,7 +41,7 @@ AC_DEFUN([gl_MATH_H],
   gl_WARN_ON_USE_PREPARE([[#include <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
+     expf expl fabsf fabsl floorf floorl fma fmaf fmal fmodf fmodl frexpf frexpl
      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])
@@ -85,6 +85,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   GNULIB_FMAF=0;      AC_SUBST([GNULIB_FMAF])
   GNULIB_FMAL=0;      AC_SUBST([GNULIB_FMAL])
   GNULIB_FMODF=0;     AC_SUBST([GNULIB_FMODF])
+  GNULIB_FMODL=0;     AC_SUBST([GNULIB_FMODL])
   GNULIB_FREXPF=0;    AC_SUBST([GNULIB_FREXPF])
   GNULIB_FREXP=0;     AC_SUBST([GNULIB_FREXP])
   GNULIB_FREXPL=0;    AC_SUBST([GNULIB_FREXPL])
@@ -143,6 +144,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   HAVE_FMAF=1;                 AC_SUBST([HAVE_FMAF])
   HAVE_FMAL=1;                 AC_SUBST([HAVE_FMAL])
   HAVE_FMODF=1;                AC_SUBST([HAVE_FMODF])
+  HAVE_FMODL=1;                AC_SUBST([HAVE_FMODL])
   HAVE_FREXPF=1;               AC_SUBST([HAVE_FREXPF])
   HAVE_ISNANF=1;               AC_SUBST([HAVE_ISNANF])
   HAVE_ISNAND=1;               AC_SUBST([HAVE_ISNAND])
@@ -197,6 +199,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_FMA=0;               AC_SUBST([REPLACE_FMA])
   REPLACE_FMAF=0;              AC_SUBST([REPLACE_FMAF])
   REPLACE_FMAL=0;              AC_SUBST([REPLACE_FMAL])
+  REPLACE_FMODL=0;             AC_SUBST([REPLACE_FMODL])
   REPLACE_FREXPF=0;            AC_SUBST([REPLACE_FREXPF])
   REPLACE_FREXP=0;             AC_SUBST([REPLACE_FREXP])
   REPLACE_FREXPL=0;            AC_SUBST([REPLACE_FREXPL])
diff --git a/modules/fmodl b/modules/fmodl
new file mode 100644 (file)
index 0000000..29b5843
--- /dev/null
@@ -0,0 +1,34 @@
+Description:
+fmodl() function: floating-point remainder function.
+
+Files:
+lib/fmodl.c
+m4/fmodl.m4
+m4/mathfunc.m4
+
+Depends-on:
+math
+fmod            [{ test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
+truncl          [{ test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+fmal            [{ test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+
+configure.ac:
+gl_FUNC_FMODL
+if test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; then
+  AC_LIBOBJ([fmodl])
+fi
+gl_MATH_MODULE_INDICATOR([fmodl])
+
+Makefile.am:
+
+Include:
+<math.h>
+
+Link:
+$(FMODL_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
index ac8760d..6394b3c 100644 (file)
@@ -55,6 +55,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's/@''GNULIB_FMAF''@/$(GNULIB_FMAF)/g' \
              -e 's/@''GNULIB_FMAL''@/$(GNULIB_FMAL)/g' \
              -e 's/@''GNULIB_FMODF''@/$(GNULIB_FMODF)/g' \
+             -e 's/@''GNULIB_FMODL''@/$(GNULIB_FMODL)/g' \
              -e 's/@''GNULIB_FREXPF''@/$(GNULIB_FREXPF)/g' \
              -e 's/@''GNULIB_FREXP''@/$(GNULIB_FREXP)/g' \
              -e 's/@''GNULIB_FREXPL''@/$(GNULIB_FREXPL)/g' \
@@ -113,6 +114,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''HAVE_FMAF''@|$(HAVE_FMAF)|g' \
              -e 's|@''HAVE_FMAL''@|$(HAVE_FMAL)|g' \
              -e 's|@''HAVE_FMODF''@|$(HAVE_FMODF)|g' \
+             -e 's|@''HAVE_FMODL''@|$(HAVE_FMODL)|g' \
              -e 's|@''HAVE_FREXPF''@|$(HAVE_FREXPF)|g' \
              -e 's|@''HAVE_ISNANF''@|$(HAVE_ISNANF)|g' \
              -e 's|@''HAVE_ISNAND''@|$(HAVE_ISNAND)|g' \
@@ -168,6 +170,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''REPLACE_FMA''@|$(REPLACE_FMA)|g' \
              -e 's|@''REPLACE_FMAF''@|$(REPLACE_FMAF)|g' \
              -e 's|@''REPLACE_FMAL''@|$(REPLACE_FMAL)|g' \
+             -e 's|@''REPLACE_FMODL''@|$(REPLACE_FMODL)|g' \
              -e 's|@''REPLACE_FREXPF''@|$(REPLACE_FREXPF)|g' \
              -e 's|@''REPLACE_FREXP''@|$(REPLACE_FREXP)|g' \
              -e 's|@''REPLACE_FREXPL''@|$(REPLACE_FREXPL)|g' \