www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Possible implicit type conversion bug with arithmetic op=

reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
Try this:

int x = 4.5;

It fails because you can't implicitly convert a floating point type to an 
int.

Similarly:

x = x + 4.5;

Also fails.

But:

x += 4.5;

Works, and 4.5 is implicitly converted to an int.

This happens with +=, -=, *=, /=, and %=.  The bitwise op= (&=, |=, <<=, >>= 
and >>>=) all issue errors because 4.5 is not integral.

I'm 99% sure this is a bug.  If so, I'll bugzilla it. 
Jun 23 2006
parent Bruno Medeiros <brunodomedeirosATgmail SPAM.com> writes:
Jarrett Billingsley wrote:
 Try this:
 
 int x = 4.5;
 
 It fails because you can't implicitly convert a floating point type to an 
 int.
 
 Similarly:
 
 x = x + 4.5;
 
 Also fails.
 
 But:
 
 x += 4.5;
 
 Works, and 4.5 is implicitly converted to an int.
 
 This happens with +=, -=, *=, /=, and %=.  The bitwise op= (&=, |=, <<=, >>= 
 and >>>=) all issue errors because 4.5 is not integral.
 
 I'm 99% sure this is a bug.  If so, I'll bugzilla it. 
 
 

Does seem like a bug to me. Do report it. -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Jun 26 2006