New module 'remainderl'.
authorBruno Haible <bruno@clisp.org>
Sat, 25 Feb 2012 19:37:43 +0000 (20:37 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 25 Feb 2012 19:37:43 +0000 (20:37 +0100)
* lib/math.in.h (remainderh): New declaration.
* lib/remainderl.c: New file.
* m4/remainderl.m4: New file.
* modules/remainderl: New file.
* m4/math_h.m4 (gl_MATH_H): Test whether remainderl is declared.
(gl_MATH_H_DEFAULTS): Initialize GNULIB_REMAINDERL, HAVE_REMAINDERL.
* modules/math (Makefile.am): Substitute GNULIB_REMAINDERL,
HAVE_REMAINDERL.
* doc/posix-functions/remainderl.texi: Mention the new module.

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

index d65430d..729c04c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2012-02-25  Bruno Haible  <bruno@clisp.org>
 
 2012-02-25  Bruno Haible  <bruno@clisp.org>
 
+       New module 'remainderl'.
+       * lib/math.in.h (remainderh): New declaration.
+       * lib/remainderl.c: New file.
+       * m4/remainderl.m4: New file.
+       * modules/remainderl: New file.
+       * m4/math_h.m4 (gl_MATH_H): Test whether remainderl is declared.
+       (gl_MATH_H_DEFAULTS): Initialize GNULIB_REMAINDERL, HAVE_REMAINDERL.
+       * modules/math (Makefile.am): Substitute GNULIB_REMAINDERL,
+       HAVE_REMAINDERL.
+       * doc/posix-functions/remainderl.texi: Mention the new module.
+
+2012-02-25  Bruno Haible  <bruno@clisp.org>
+
        Tests for module 'remainderf'.
        * modules/remainderf-tests: New file.
        * tests/test-remainderf.c: New file.
        Tests for module 'remainderf'.
        * modules/remainderf-tests: New file.
        * tests/test-remainderf.c: New file.
index 8cfd104..bd05a60 100644 (file)
@@ -4,15 +4,15 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/remainderl.html}
 
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/remainderl.html}
 
-Gnulib module: ---
+Gnulib module: remainderl
 
 Portability problems fixed by Gnulib:
 @itemize
 
 Portability problems 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, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 4.0, Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS.
 @end itemize
 
 Portability problems not 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, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 4.0, Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS.
 @end itemize
 @end itemize
index 09510fa..852cead 100644 (file)
@@ -926,6 +926,20 @@ _GL_WARN_ON_USE (remainder, "remainder is unportable - "
 # endif
 #endif
 
 # endif
 #endif
 
+#if @GNULIB_REMAINDERL@
+# if !@HAVE_REMAINDERL@
+_GL_FUNCDECL_SYS (remainderl, long double, (long double x, long double y));
+# endif
+_GL_CXXALIAS_SYS (remainderl, long double, (long double x, long double y));
+_GL_CXXALIASWARN (remainderl);
+#elif defined GNULIB_POSIXCHECK
+# undef remainderl
+# if HAVE_RAW_DECL_REMAINDERL
+_GL_WARN_ON_USE (remainderl, "remainderl is unportable - "
+                 "use gnulib module remainderl for portability");
+# endif
+#endif
+
 
 #if @GNULIB_RINTF@
 # if !@HAVE_RINTF@
 
 #if @GNULIB_RINTF@
 # if !@HAVE_RINTF@
diff --git a/lib/remainderl.c b/lib/remainderl.c
new file mode 100644 (file)
index 0000000..b43592a
--- /dev/null
@@ -0,0 +1,39 @@
+/* Remainder.
+   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
+remainderl (long double x, long double y)
+{
+  return remainder (x, y);
+}
+
+#else
+
+long double
+remainderl (long double x, long double y)
+{
+  long double i = roundl (x / y);
+  return fmal (- i, y, x);
+}
+
+#endif
index d5a0a74..c3c5196 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 61
+# math_h.m4 serial 62
 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,
 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,
@@ -43,7 +43,7 @@ AC_DEFUN([gl_MATH_H],
      ceilf ceill copysign copysignf copysignl cosf cosl coshf
      expf expl fabsf fabsl floorf floorl fma fmaf fmal fmodf fmodl frexpf frexpl
      ldexpf ldexpl logb logf logl log10f modff modfl powf
      ceilf ceill copysign copysignf copysignl cosf cosl coshf
      expf expl fabsf fabsl floorf floorl fma fmaf fmal fmodf fmodl frexpf frexpl
      ldexpf ldexpl logb logf logl log10f modff modfl powf
-     remainder remainderf
+     remainder remainderf remainderl
      rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl
      tanf tanl tanhf trunc truncf truncl])
 ])
      rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl
      tanf tanl tanhf trunc truncf truncl])
 ])
@@ -107,6 +107,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   GNULIB_POWF=0;       AC_SUBST([GNULIB_POWF])
   GNULIB_REMAINDER=0;  AC_SUBST([GNULIB_REMAINDER])
   GNULIB_REMAINDERF=0; AC_SUBST([GNULIB_REMAINDERF])
   GNULIB_POWF=0;       AC_SUBST([GNULIB_POWF])
   GNULIB_REMAINDER=0;  AC_SUBST([GNULIB_REMAINDER])
   GNULIB_REMAINDERF=0; AC_SUBST([GNULIB_REMAINDERF])
+  GNULIB_REMAINDERL=0; AC_SUBST([GNULIB_REMAINDERL])
   GNULIB_RINT=0;       AC_SUBST([GNULIB_RINT])
   GNULIB_RINTF=0;      AC_SUBST([GNULIB_RINTF])
   GNULIB_RINTL=0;      AC_SUBST([GNULIB_RINTL])
   GNULIB_RINT=0;       AC_SUBST([GNULIB_RINT])
   GNULIB_RINTF=0;      AC_SUBST([GNULIB_RINTF])
   GNULIB_RINTL=0;      AC_SUBST([GNULIB_RINTL])
@@ -161,6 +162,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   HAVE_POWF=1;                 AC_SUBST([HAVE_POWF])
   HAVE_REMAINDER=1;            AC_SUBST([HAVE_REMAINDER])
   HAVE_REMAINDERF=1;           AC_SUBST([HAVE_REMAINDERF])
   HAVE_POWF=1;                 AC_SUBST([HAVE_POWF])
   HAVE_REMAINDER=1;            AC_SUBST([HAVE_REMAINDER])
   HAVE_REMAINDERF=1;           AC_SUBST([HAVE_REMAINDERF])
+  HAVE_REMAINDERL=1;           AC_SUBST([HAVE_REMAINDERL])
   HAVE_RINT=1;                 AC_SUBST([HAVE_RINT])
   HAVE_RINTF=1;                AC_SUBST([HAVE_RINTF])
   HAVE_RINTL=1;                AC_SUBST([HAVE_RINTL])
   HAVE_RINT=1;                 AC_SUBST([HAVE_RINT])
   HAVE_RINTF=1;                AC_SUBST([HAVE_RINTF])
   HAVE_RINTL=1;                AC_SUBST([HAVE_RINTL])
diff --git a/m4/remainderl.m4 b/m4/remainderl.m4
new file mode 100644 (file)
index 0000000..35f578c
--- /dev/null
@@ -0,0 +1,59 @@
+# remainderl.m4 serial 1
+dnl Copyright (C) 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_REMAINDERL],
+[
+  AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
+  AC_REQUIRE([gl_FUNC_REMAINDER])
+
+  dnl Test whether remainderl() exists. Assume that remainderl(), if it exists, is
+  dnl defined in the same library as remainder().
+  save_LIBS="$LIBS"
+  LIBS="$LIBS $REMAINDER_LIBM"
+  AC_CACHE_CHECK([for remainderl],
+    [gl_cv_func_remainderl],
+    [
+      AC_LINK_IFELSE(
+        [AC_LANG_PROGRAM(
+           [[#ifndef __NO_MATH_INLINES
+             # define __NO_MATH_INLINES 1 /* for glibc */
+             #endif
+             #include <math.h>
+             long double (*funcptr) (long double, long double) = remainderl;
+             long double x;
+             long double y;]],
+           [[return funcptr (x, y) > 1
+                    || remainderl (x, y) > 1;]])],
+        [gl_cv_func_remainderl=yes],
+        [gl_cv_func_remainderl=no])
+    ])
+  LIBS="$save_LIBS"
+  if test $gl_cv_func_remainderl = yes; then
+    REMAINDERL_LIBM="$REMAINDER_LIBM"
+  else
+    HAVE_REMAINDERL=0
+    dnl Find libraries needed to link lib/remainderl.c.
+    if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
+      REMAINDERL_LIBM="$REMAINDER_LIBM"
+    else
+      AC_REQUIRE([gl_FUNC_ROUNDL])
+      AC_REQUIRE([gl_FUNC_FMAL])
+      REMAINDERL_LIBM=
+      dnl Append $ROUNDL_LIBM to REMAINDERL_LIBM, avoiding gratuitous duplicates.
+      case " $REMAINDERL_LIBM " in
+        *" $ROUNDL_LIBM "*) ;;
+        *) REMAINDERL_LIBM="$REMAINDERL_LIBM $ROUNDL_LIBM" ;;
+      esac
+      dnl Append $FMAL_LIBM to REMAINDERL_LIBM, avoiding gratuitous duplicates.
+      case " $REMAINDERL_LIBM " in
+        *" $FMAL_LIBM "*) ;;
+        *) REMAINDERL_LIBM="$REMAINDERL_LIBM $FMAL_LIBM" ;;
+      esac
+    fi
+  fi
+  AC_SUBST([REMAINDERL_LIBM])
+])
index 4265359..1cef3b3 100644 (file)
@@ -76,6 +76,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's/@''GNULIB_POWF''@/$(GNULIB_POWF)/g' \
              -e 's/@''GNULIB_REMAINDER''@/$(GNULIB_REMAINDER)/g' \
              -e 's/@''GNULIB_REMAINDERF''@/$(GNULIB_REMAINDERF)/g' \
              -e 's/@''GNULIB_POWF''@/$(GNULIB_POWF)/g' \
              -e 's/@''GNULIB_REMAINDER''@/$(GNULIB_REMAINDER)/g' \
              -e 's/@''GNULIB_REMAINDERF''@/$(GNULIB_REMAINDERF)/g' \
+             -e 's/@''GNULIB_REMAINDERL''@/$(GNULIB_REMAINDERL)/g' \
              -e 's/@''GNULIB_RINT''@/$(GNULIB_RINT)/g' \
              -e 's/@''GNULIB_RINTF''@/$(GNULIB_RINTF)/g' \
              -e 's/@''GNULIB_RINTL''@/$(GNULIB_RINTL)/g' \
              -e 's/@''GNULIB_RINT''@/$(GNULIB_RINT)/g' \
              -e 's/@''GNULIB_RINTF''@/$(GNULIB_RINTF)/g' \
              -e 's/@''GNULIB_RINTL''@/$(GNULIB_RINTL)/g' \
@@ -130,6 +131,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''HAVE_POWF''@|$(HAVE_POWF)|g' \
              -e 's|@''HAVE_REMAINDER''@|$(HAVE_REMAINDER)|g' \
              -e 's|@''HAVE_REMAINDERF''@|$(HAVE_REMAINDERF)|g' \
              -e 's|@''HAVE_POWF''@|$(HAVE_POWF)|g' \
              -e 's|@''HAVE_REMAINDER''@|$(HAVE_REMAINDER)|g' \
              -e 's|@''HAVE_REMAINDERF''@|$(HAVE_REMAINDERF)|g' \
+             -e 's|@''HAVE_REMAINDERL''@|$(HAVE_REMAINDERL)|g' \
              -e 's|@''HAVE_RINT''@|$(HAVE_RINT)|g' \
              -e 's|@''HAVE_RINTF''@|$(HAVE_RINTF)|g' \
              -e 's|@''HAVE_RINTL''@|$(HAVE_RINTL)|g' \
              -e 's|@''HAVE_RINT''@|$(HAVE_RINT)|g' \
              -e 's|@''HAVE_RINTF''@|$(HAVE_RINTF)|g' \
              -e 's|@''HAVE_RINTL''@|$(HAVE_RINTL)|g' \
diff --git a/modules/remainderl b/modules/remainderl
new file mode 100644 (file)
index 0000000..20daae7
--- /dev/null
@@ -0,0 +1,34 @@
+Description:
+remainderl() function: floating-point remainder function.
+
+Files:
+lib/remainderl.c
+m4/remainderl.m4
+m4/mathfunc.m4
+
+Depends-on:
+math
+remainder       [test $HAVE_REMAINDERL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
+roundl          [test $HAVE_REMAINDERL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+fmal            [test $HAVE_REMAINDERL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+
+configure.ac:
+gl_FUNC_REMAINDERL
+if test $HAVE_REMAINDERL = 0; then
+  AC_LIBOBJ([remainderl])
+fi
+gl_MATH_MODULE_INDICATOR([remainderl])
+
+Makefile.am:
+
+Include:
+<math.h>
+
+Link:
+$(REMAINDERL_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible