New integer promotion rules
rumbu
rumbu at rumbu.ro
Thu Jan 18 17:54:59 UTC 2018
On Thursday, 18 January 2018 at 12:51:48 UTC, Dominikus Dittes
Scherkl wrote:
> On Thursday, 18 January 2018 at 06:05:08 UTC, rumbu wrote:
>> On Thursday, 18 January 2018 at 02:30:17 UTC, Rubn wrote:
>>> On Wednesday, 17 January 2018 at 22:30:11 UTC, rumbu wrote:
>>>> code like "m = n < 0 ? -n : n" doesn't worth a wrapper
>>>
>>> That code is worth a wrapper, it's called "abs"...
>>>
>>> m = abs(n);
>>
>> Well, since I'm in the learn forum and you seem to have a
>> response to anything, can you help me translate this line
>> under the new integer promotion rules?
>>
>> https://github.com/rumbu13/decimal/blob/master/src/decimal/decimal.d#L7804
>>
>> Thanks.
>
> target = isNegative ? cast(Unsigned!T)(-c) : cast(Unsigned!T)c;
>
> That would have been better even before the change, because the
> operator '-' used on unsigned types is likely to produce
> unexpected results, if the behaviour is defined at all.
I don't think so:
ulong c = 128;
bool isNegative = true;
byte target = isNegative ? -cast(ubyte)c : cast(ubyte)c;
Error Deprecation: integral promotion not done for
`-cast(ubyte)c`, use '-transition=intpromote' switch or
`-cast(int)(cast(ubyte)c)`
More information about the Digitalmars-d-learn
mailing list