New integer promotion rules

rumbu rumbu at rumbu.ro
Wed Jan 17 20:08:53 UTC 2018


On Wednesday, 17 January 2018 at 19:54:50 UTC, ag0aep6g wrote:
> On 01/17/2018 08:40 PM, rumbu wrote:
>> This started in the last DMD version (2.078):
>> 
>> byte b = -10;
>> ulong u = b < 0 ? -b : b;
>> 
>> //Deprecation: integral promotion not done for `-b`, use 
>> '-transition=intpromote' switch or `-cast(int)(b)
>> 
>> Why do I need a to promote a byte to int to obtain an ulong? 
>> Even in the extreme case where b is byte.min, -byte.min as 
>> unsigned is exactly what i need: 128;
>
> Actually, for b = byte.min, you get u = 18446744073709551488.

Wrong, compiled with 2.077 or 2.078 with -transition=intpromote

byte b = byte.min;
ulong u = -b;
writeln(u);

outputs correctly 128

>
> 2.078 is starting to fix this so that you get 128. But that's a 
> breaking change, so you have to use the compiler switch or the 
> cast for a couple releases.
>
> In the changelog: 
> https://dlang.org/changelog/2.078.0.html#fix16997




More information about the Digitalmars-d-learn mailing list