unsigned / double propagation weirdness?

Andrew Pinski pinskia@physics.uc.edu
Mon Feb 23 15:53:00 GMT 2004


On Feb 23, 2004, at 06:42, Richard Guenther wrote:

> Hi, I'm getting confusing (but consistent along a lot of different 
> compilers) results out of this testcase:
>
> int main(int argc, char **argv)
> {
>   double dm = 1.0;
>   unsigned int i = 1;
>   if (-i*dm != -((double)i)*dm)
>     abort();
>   return 0;
> }


The reason is that -i*dm really is (-i)*dm which is really 
((double)(-i))*dm.

So it turns out to be ((unsigned int)-1) * 1.0 which is different from 
-(double)(1) * 1.0.
So it just misunderstanding on where the unary operator, -, applies to 
and when the cast
happens.

Thanks,
Andrew Pinski



More information about the Gcc mailing list