Annoyance with new integer promotion deprecations
Steven Schveighoffer
schveiguy at yahoo.com
Mon Feb 5 23:34:59 UTC 2018
On 2/5/18 6:09 PM, Adam D. Ruppe wrote:
> On Monday, 5 February 2018 at 22:52:41 UTC, Steven Schveighoffer wrote:
>> But I can't see why there is controversy over negation of byte turning
>> into an int. I can't see why anyone would expect:
>>
>> int x = -b;
>>
>> when b is -128, to set x to -128. The integer promotion makes complete
>> sense to me.
>
> Do you feel the same way about
>
> float x = 1/2;
>
> ?
Not really. But it is a good counter-argument.
In a way, it's the fact that it's a corner case which makes this more
sinister. For all bytes *except* byte.min, the behavior is the same
regardless of whether integer promotion is used or not. So when this bug
actually occurs, it's going to be in code that "worked for years". And
in some cases was ported from C and worked there.
But for integer division and assignment to float, it's quite obvious
that it doesn't work with almost all combinations.
-Steve
More information about the Digitalmars-d
mailing list