From 93c29eb8fc3e97d269fc8939ff47454702e7c585 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 25 Feb 2012 20:37:43 +0100 Subject: [PATCH] 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. --- ChangeLog | 13 ++++++++ doc/posix-functions/remainderl.texi | 8 ++--- lib/math.in.h | 14 +++++++++ lib/remainderl.c | 39 ++++++++++++++++++++++++ m4/math_h.m4 | 6 ++-- m4/remainderl.m4 | 59 +++++++++++++++++++++++++++++++++++++ modules/math | 2 ++ modules/remainderl | 34 +++++++++++++++++++++ 8 files changed, 169 insertions(+), 6 deletions(-) create mode 100644 lib/remainderl.c create mode 100644 m4/remainderl.m4 create mode 100644 modules/remainderl diff --git a/ChangeLog b/ChangeLog index d65430d99..729c04c9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2012-02-25 Bruno Haible + 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 + Tests for module 'remainderf'. * modules/remainderf-tests: New file. * tests/test-remainderf.c: New file. diff --git a/doc/posix-functions/remainderl.texi b/doc/posix-functions/remainderl.texi index 8cfd1047d..bd05a6029 100644 --- a/doc/posix-functions/remainderl.texi +++ b/doc/posix-functions/remainderl.texi @@ -4,15 +4,15 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/remainderl.html} -Gnulib module: --- +Gnulib module: remainderl 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 -@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 diff --git a/lib/math.in.h b/lib/math.in.h index 09510fa01..852cead1a 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -926,6 +926,20 @@ _GL_WARN_ON_USE (remainder, "remainder is unportable - " # 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@ diff --git a/lib/remainderl.c b/lib/remainderl.c new file mode 100644 index 000000000..b43592a64 --- /dev/null +++ b/lib/remainderl.c @@ -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 . */ + +#include + +/* Specification. */ +#include + +#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 diff --git a/m4/math_h.m4 b/m4/math_h.m4 index d5a0a7470..c3c51964c 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -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, @@ -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 - remainder remainderf + remainder remainderf remainderl 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_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]) @@ -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_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]) diff --git a/m4/remainderl.m4 b/m4/remainderl.m4 new file mode 100644 index 000000000..35f578c41 --- /dev/null +++ b/m4/remainderl.m4 @@ -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 + 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]) +]) diff --git a/modules/math b/modules/math index 4265359f7..1cef3b38f 100644 --- a/modules/math +++ b/modules/math @@ -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_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' \ @@ -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_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' \ diff --git a/modules/remainderl b/modules/remainderl new file mode 100644 index 000000000..20daae73d --- /dev/null +++ b/modules/remainderl @@ -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: + + +Link: +$(REMAINDERL_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible -- 2.11.0