This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: valarray<double>::operator%() not working
- From: Lance Olav Eastgate <lance at ccmr dot cornell dot edu>
- To: Paolo Carlini <pcarlini at unitus dot it>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Fri, 22 Feb 2002 14:06:33 -0500 (EST)
- Subject: Re: valarray<double>::operator%() not working
> Lance Olav Eastgate wrote:
>
> >When I try to use the binary operator% or operator%= with valarray<double>
> >this doesn't work (in gcc 3.0.2). The reason, as far as I understand, is
> >that operator% is only defined for integers. The element-by-element
> >modulus in _DEFINE_ARRAY_FUNCTION (in valarray_array.h, line 419, gcc
> >3.0.2) thus doesn't work when _Tp is a double. Thus for two doubles or
> >floats, std::fmod (or similar) needs to be used.
> >
> >Perhaps the operator% etc could be overloaded to take two doubles?
> >
> Hi. I know all of this seems obvious to you, but could you possibly post
> a short self-contained testcase demonstrating the problem?
>
> Thanks,
> Paolo.
Here is a self-contained test-case (all four statements using the %
operator produce errors individually):
#include <valarray>
int main() {
std::valarray<double> u(10), v(22.0, 10), w(2.3, 10);
u = v % 2.3;
u = v % w;
v %= 2.3;
v %= w;
}
Thanks,
Lance