New integer promotion rules
Dominikus Dittes Scherkl
dominikus.scherkl at continental-corporation.com
Thu Jan 18 12:51:48 UTC 2018
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.
More information about the Digitalmars-d-learn
mailing list