Integer promotion... what I'm missing? (It's monday...)

Paolo Invernizzi arathorn at NOSPAM_fastwebnet.it
Wed Jun 28 00:15:07 PDT 2006


You both are true, and I know about Two's complement...

But, as  others in the thread pointed out, that's just a way of 
"represent" a number, and, worst, in this case, they are just "constant":

   uint a = 16;
   int b = -1;
   assert(b < a);

No ambiguity at all. This can be folded.

And in the real world, -1 is less than 16. So, as one of the main 
principle of the D programming language is to minimize the risks of 
bugs, I feel that at least a Warning should be raised for that code...

But really, it's just a minor glitch...

Cheers

---
Paolo


Kirk McDonald wrote:
> Alexander Panek wrote:
>> If you take a look at how comparison works, you'll know why this one 
>> fails.
>>
>> Lets take an uint a = 16; as in your example:
>> 00000000 00000000 00000000 00010000
>>
>> And now a signed integer with the value -1:
>> 10000000 00000000 00000000 00000001
>>
> 
> Your point still stands, but -1 is represented as:
> 11111111 11111111 11111111 11111111
> 
> http://en.wikipedia.org/wiki/Two%27s_complement
> 
>> You might guess which number is bigger, when our comparison is done 
>> binary (and after all, that's what the processor does) :)
>>
>> Regards,
>> Alex
>>
>> Paolo Invernizzi wrote:
>>
>>> Hi all,
>>>
>>> What I'm missing?
>>>
>>>     uint a = 16;
>>>     int b = -1;
>>>     assert( b < a ); // this fails! I was expecting that -1 < 16
>>>
>>> Thanks
>>>
>>> ---
>>> Paolo



More information about the Digitalmars-d-learn mailing list