Weird const behavior

Marko marko at gmail.com
Thu Dec 20 17:06:02 UTC 2018


On Thursday, 20 December 2018 at 15:15:42 UTC, Andrea Fontana 
wrote:
> On Thursday, 20 December 2018 at 14:49:10 UTC, Marko wrote:
>> But is this right? I mean if they are equal shouldn't they 
>> have the same behavior?
>
> I don't think so:
>
>     float a = 1.0;
>     long b = 1;
>
>     writeln(a == b);
>     writeln(a/2 == b/2);

Of course you can play around:

     uint  positive_one = 1;
     short minus_one = -1;
     uint max_int = 4294967295;

     writeln(minus_one > positive_one); // true
     writeln(minus_one == max_int); // true

Because promotion and implicit casting. But like I said this is 
sometimes confusion, and on the OP example it's worth.

Marko.


More information about the Digitalmars-d-learn mailing list