On Sunday, 27 April 2014 at 00:07:22 UTC, Adam D. Ruppe wrote:
On Sunday, 27 April 2014 at 00:01:21 UTC, Andrei Alexandrescu wrote:
Oops. No bug. -- Andrei

Nah, sorry, that was my giant mistake, I didn't actually do the math before saying "check your math" and let my brain get confused into thinking 10000000 was 128, but it is actually -128 in twos complement, the high bit is set so it is negative.

Yeah, or just remember that signed representation are evenly split between negatives and positives, but positives get the '0':

Positives: [0 .. high);
Negatives: [-high .. 0);

It's an interesting source of bugs, and the reason you should "never" store an absolute value in a singed object. Since "-int.min" is still "int.min".

Reply via email to