On MSVC 9, I'm seeing this link error: source='test-remainder.c' object='test-remainder.obj' libtool=no \ DEPDIR=.deps depmode=none /bin/sh ../build-aux/depcomp \ /home/bruno/msvc/compile cl -nologo -DHAVE_CONFIG_H -I. -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I. -I.. -I./.. -I../gllib -I./../gllib -D_WIN32_WINNT=_WIN32_WINNT_WINXP -I/usr/local/msvc/include -MD -c -o test-remainder.obj `cygpath -w 'test-remainder.c'` test-remainder.c test-remainder.c(24) : error C2065: 'remainder': nichtdeklarierter Bezeichner test-remainder.c(24) : error C2099: Initialisierung ist keine Konstante make[4]: *** [test-remainder.obj] Error 2
This fixes it by providing an implementation for this function. In passing, also fix the missing declaration problem on IRIX 5.3 (untested). 2012-02-25 Bruno Haible <br...@clisp.org> remainder: Support for MSVC. * lib/math.in.h (remainder): New declaration. * lib/remainder.c: New file. * m4/remainder.m4: New file. * modules/remainder (Files): Add lib/remainder.c, m4/remainder.m4. (Depends-on): Add math, round, fma. (configure.ac): Use results of gl_FUNC_REMAINDER. * m4/math_h.m4 (gl_MATH_H): Test whether remainder is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_REMAINDER, HAVE_REMAINDER, HAVE_DECL_REMAINDER. * modules/math (Makefile.am): Substitute GNULIB_REMAINDER, HAVE_REMAINDER, HAVE_DECL_REMAINDER. * tests/test-math-c++.cc: Check the declaration of remainder. * doc/posix-functions/remainder.texi: Mention that the MSVC and IRIX 5 problems are fixed. =============================== lib/remainder.c =============================== /* 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> double remainder (double x, double y) { double i = round (x / y); return fma (- i, y, x); } =============================== m4/remainder.m4 =============================== # remainder.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_REMAINDER], [ AC_REQUIRE([gl_MATH_H_DEFAULTS]) dnl Test whether remainder() is declared. On IRIX 5.3 it is not declared. AC_CHECK_DECL([remainder], , [HAVE_DECL_REMAINDER=0], [[#include <math.h>]]) REMAINDER_LIBM= AC_CACHE_CHECK([whether remainder() can be used without linking with libm], [gl_cv_func_remainder_no_libm], [ AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[#ifndef __NO_MATH_INLINES # define __NO_MATH_INLINES 1 /* for glibc */ #endif #include <math.h> double x; double y;]], [[return remainder (x, y) > 1;]])], [gl_cv_func_remainder_no_libm=yes], [gl_cv_func_remainder_no_libm=no]) ]) if test $gl_cv_func_remainder_no_libm = no; then AC_CACHE_CHECK([whether remainder() can be used with libm], [gl_cv_func_remainder_in_libm], [ save_LIBS="$LIBS" LIBS="$LIBS -lm" AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[#ifndef __NO_MATH_INLINES # define __NO_MATH_INLINES 1 /* for glibc */ #endif #include <math.h> double x; double y;]], [[return remainder (x, y) > 1;]])], [gl_cv_func_remainder_in_libm=yes], [gl_cv_func_remainder_in_libm=no]) LIBS="$save_LIBS" ]) if test $gl_cv_func_remainder_in_libm = yes; then REMAINDER_LIBM=-lm fi fi if test $gl_cv_func_remainder_no_libm = no \ && test $gl_cv_func_remainder_in_libm = no; then HAVE_REMAINDER=0 dnl Find libraries needed to link lib/remainder.c. AC_REQUIRE([gl_FUNC_ROUND]) AC_REQUIRE([gl_FUNC_FMA]) REMAINDER_LIBM= dnl Append $ROUND_LIBM to REMAINDER_LIBM, avoiding gratuitous duplicates. case " $REMAINDER_LIBM " in *" $ROUND_LIBM "*) ;; *) REMAINDER_LIBM="$REMAINDER_LIBM $ROUND_LIBM" ;; esac dnl Append $FMA_LIBM to REMAINDER_LIBM, avoiding gratuitous duplicates. case " $REMAINDER_LIBM " in *" $FMA_LIBM "*) ;; *) REMAINDER_LIBM="$REMAINDER_LIBM $FMA_LIBM" ;; esac fi AC_SUBST([REMAINDER_LIBM]) ]) =============================================================================== --- ChangeLog.orig Sat Feb 25 18:25:54 2012 +++ ChangeLog Sat Feb 25 18:25:14 2012 @@ -1,5 +1,22 @@ 2012-02-25 Bruno Haible <br...@clisp.org> + remainder: Support for MSVC. + * lib/remainder.c: New file. + * m4/remainder.m4: New file. + * doc/posix-functions/remainder.texi: Mention that the MSVC and IRIX 5 + problems are fixed. + * lib/math.in.h (remainder): New declaration. + * m4/math_h.m4 (gl_MATH_H): Test whether remainder is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_REMAINDER, HAVE_REMAINDER, + HAVE_DECL_REMAINDER. + * modules/math (Makefile.am): Substitute GNULIB_REMAINDER, + HAVE_REMAINDER, HAVE_DECL_REMAINDER. + * modules/remadiner (Files): Add lib/remainder.c, m4/remainder.m4. + (Depends-on): Add math, round, fma. + (configure.ac): Use results of gl_FUNC_REMAINDER. + +2012-02-25 Bruno Haible <br...@clisp.org> + Tests for module 'fmodl'. * modules/fmodl-tests: New file. * tests/test-fmodl.c: New file. --- doc/posix-functions/remainder.texi.orig Sat Feb 25 18:25:54 2012 +++ doc/posix-functions/remainder.texi Sat Feb 25 17:31:14 2012 @@ -8,10 +8,6 @@ Portability problems fixed by Gnulib: @itemize -@end itemize - -Portability problems not fixed by Gnulib: -@itemize @item This function is missing on some platforms: MSVC 9. @@ -19,3 +15,7 @@ This function is not declared on some platforms: IRIX 5.3. @end itemize + +Portability problems not fixed by Gnulib: +@itemize +@end itemize --- lib/math.in.h.orig Sat Feb 25 18:25:54 2012 +++ lib/math.in.h Sat Feb 25 17:45:34 2012 @@ -898,6 +898,21 @@ #endif +#if @GNULIB_REMAINDER@ +# if !@HAVE_REMAINDER@ || !@HAVE_DECL_REMAINDER@ +_GL_FUNCDECL_SYS (remainder, double, (double x, double y)); +# endif +_GL_CXXALIAS_SYS (remainder, double, (double x, double y)); +_GL_CXXALIASWARN (remainder); +#elif defined GNULIB_POSIXCHECK +# undef remainder +# if HAVE_RAW_DECL_REMAINDER +_GL_WARN_ON_USE (remainder, "remainder is unportable - " + "use gnulib module remainder for portability"); +# endif +#endif + + #if @GNULIB_RINTF@ # if !@HAVE_RINTF@ _GL_FUNCDECL_SYS (rintf, float, (float x)); --- m4/math_h.m4.orig Sat Feb 25 18:25:54 2012 +++ m4/math_h.m4 Sat Feb 25 17:45:57 2012 @@ -1,4 +1,4 @@ -# math_h.m4 serial 59 +# math_h.m4 serial 60 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,6 +43,7 @@ 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 rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl tanf tanl tanhf trunc truncf truncl]) ]) @@ -104,6 +105,7 @@ GNULIB_MODFF=0; AC_SUBST([GNULIB_MODFF]) GNULIB_MODFL=0; AC_SUBST([GNULIB_MODFL]) GNULIB_POWF=0; AC_SUBST([GNULIB_POWF]) + GNULIB_REMAINDER=0; AC_SUBST([GNULIB_REMAINDER]) GNULIB_RINT=0; AC_SUBST([GNULIB_RINT]) GNULIB_RINTF=0; AC_SUBST([GNULIB_RINTF]) GNULIB_RINTL=0; AC_SUBST([GNULIB_RINTL]) @@ -156,6 +158,7 @@ HAVE_MODFF=1; AC_SUBST([HAVE_MODFF]) HAVE_MODFL=1; AC_SUBST([HAVE_MODFL]) HAVE_POWF=1; AC_SUBST([HAVE_POWF]) + HAVE_REMAINDER=1; AC_SUBST([HAVE_REMAINDER]) HAVE_RINT=1; AC_SUBST([HAVE_RINT]) HAVE_RINTF=1; AC_SUBST([HAVE_RINTF]) HAVE_RINTL=1; AC_SUBST([HAVE_RINTL]) @@ -180,6 +183,7 @@ HAVE_DECL_LDEXPL=1; AC_SUBST([HAVE_DECL_LDEXPL]) HAVE_DECL_LOGB=1; AC_SUBST([HAVE_DECL_LOGB]) HAVE_DECL_LOGL=1; AC_SUBST([HAVE_DECL_LOGL]) + HAVE_DECL_REMAINDER=1; AC_SUBST([HAVE_DECL_REMAINDER]) HAVE_DECL_ROUND=1; AC_SUBST([HAVE_DECL_ROUND]) HAVE_DECL_ROUNDF=1; AC_SUBST([HAVE_DECL_ROUNDF]) HAVE_DECL_ROUNDL=1; AC_SUBST([HAVE_DECL_ROUNDL]) --- modules/math.orig Sat Feb 25 18:25:54 2012 +++ modules/math Sat Feb 25 17:46:13 2012 @@ -74,6 +74,7 @@ -e 's/@''GNULIB_MODFF''@/$(GNULIB_MODFF)/g' \ -e 's/@''GNULIB_MODFL''@/$(GNULIB_MODFL)/g' \ -e 's/@''GNULIB_POWF''@/$(GNULIB_POWF)/g' \ + -e 's/@''GNULIB_REMAINDER''@/$(GNULIB_REMAINDER)/g' \ -e 's/@''GNULIB_RINT''@/$(GNULIB_RINT)/g' \ -e 's/@''GNULIB_RINTF''@/$(GNULIB_RINTF)/g' \ -e 's/@''GNULIB_RINTL''@/$(GNULIB_RINTL)/g' \ @@ -126,6 +127,7 @@ -e 's|@''HAVE_MODFF''@|$(HAVE_MODFF)|g' \ -e 's|@''HAVE_MODFL''@|$(HAVE_MODFL)|g' \ -e 's|@''HAVE_POWF''@|$(HAVE_POWF)|g' \ + -e 's|@''HAVE_REMAINDER''@|$(HAVE_REMAINDER)|g' \ -e 's|@''HAVE_RINT''@|$(HAVE_RINT)|g' \ -e 's|@''HAVE_RINTF''@|$(HAVE_RINTF)|g' \ -e 's|@''HAVE_RINTL''@|$(HAVE_RINTL)|g' \ @@ -150,6 +152,7 @@ -e 's|@''HAVE_DECL_LDEXPL''@|$(HAVE_DECL_LDEXPL)|g' \ -e 's|@''HAVE_DECL_LOGB''@|$(HAVE_DECL_LOGB)|g' \ -e 's|@''HAVE_DECL_LOGL''@|$(HAVE_DECL_LOGL)|g' \ + -e 's|@''HAVE_DECL_REMAINDER''@|$(HAVE_DECL_REMAINDER)|g' \ -e 's|@''HAVE_DECL_ROUND''@|$(HAVE_DECL_ROUND)|g' \ -e 's|@''HAVE_DECL_ROUNDF''@|$(HAVE_DECL_ROUNDF)|g' \ -e 's|@''HAVE_DECL_ROUNDL''@|$(HAVE_DECL_ROUNDL)|g' \ --- modules/remainder.orig Sat Feb 25 18:25:54 2012 +++ modules/remainder Sat Feb 25 18:01:51 2012 @@ -2,12 +2,21 @@ remainder() function: floating-point remainder function. Files: +lib/remainder.c +m4/remainder.m4 m4/mathfunc.m4 Depends-on: +math +round [test $HAVE_REMAINDER = 0] +fma [test $HAVE_REMAINDER = 0] configure.ac: -gl_COMMON_DOUBLE_MATHFUNC([remainder]) +gl_FUNC_REMAINDER +if test $HAVE_REMAINDER = 0; then + AC_LIBOBJ([remainder]) +fi +gl_MATH_MODULE_INDICATOR([remainder]) Makefile.am: --- tests/test-math-c++.cc.orig Sat Feb 25 18:25:54 2012 +++ tests/test-math-c++.cc Sat Feb 25 18:25:43 2012 @@ -205,7 +205,7 @@ #endif //SIGNATURE_CHECK (GNULIB_NAMESPACE::pow, double, (double, double)); -//SIGNATURE_CHECK (GNULIB_NAMESPACE::remainder, double, (double, double)); +SIGNATURE_CHECK (GNULIB_NAMESPACE::remainder, double, (double, double)); #if GNULIB_TEST_RINTF SIGNATURE_CHECK (GNULIB_NAMESPACE::rintf, float, (float));