April 27, 2014 Re: possible bug in std.conv.parse | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | ah, i see: if (radix == 10) return parse!Target(s); in Target parse(Target, Source)(ref Source s, uint radix) it cheating a little and using 'general' decimal number parser, which accepts '+' and '-'. for other bases it uses another code though, where '+' and '-' threats as digits, which leads to error. i think that it should either not accept sign in any radix, or accept always (given the resulting type is signed, of course). the later is much more logical if you'll ask me. |
April 27, 2014 Re: possible bug in std.conv.parse | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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".
|
Copyright © 1999-2021 by the D Language Foundation