Is this a bug or a VERY sneaky case?

Rumbu rumbu at rumbu.ro
Sat Dec 25 17:43:29 UTC 2021


On Saturday, 25 December 2021 at 14:55:29 UTC, rempas wrote:
> On Saturday, 25 December 2021 at 13:39:14 UTC, Temtaime wrote:
>> To get correct results use
>>
>> fnum = u64(-num) + 1;
>>
>> there's no bug.
>>
> Weird. It truly works but why isn't this necessary for other 
> types as well?
>

Because others are promoted to int according to integer promotion 
rules.

https://dlang.org/spec/type.html#integer-promotions

so ```-num + 1``` gets compiled as ```cast(int)(-num) + 
cast(int)1``` as long as num is byte, short, ubyte, ushort, bool, 
char or wchar.



>> Also get rid of your *_MAX, *_MIN.
>> Use u8.max, i8.min built-in properties etc.
>>
> Oh, didn't knew about that! Thanks!




More information about the Digitalmars-d mailing list