Re: possible bug in std.conv.parse

2014-04-27 Thread monarch_dodra via Digitalmars-d
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

possible bug in std.conv.parse

2014-04-26 Thread ketmar via Digitalmars-d
this code: std.conv.parse!byte(-128) throws error: Overflow in integral conversion. but this is obviously not true, as signed byte can hold such value. the question is: is it bug, or it's intended behavior to limit signed integrals to values which can be safely abs()ed?

Re: possible bug in std.conv.parse

2014-04-26 Thread bearophile via Digitalmars-d
ketmar: this code: std.conv.parse!byte(-128) throws error: Overflow in integral conversion. but this is obviously not true, as signed byte can hold such value. the question is: is it bug, or it's intended behavior to limit signed integrals to values which can be safely abs()ed? This code

Re: possible bug in std.conv.parse

2014-04-26 Thread Adam D. Ruppe via Digitalmars-d
On Saturday, 26 April 2014 at 23:36:28 UTC, ketmar wrote: this code: std.conv.parse!byte(-128) throws error: Overflow in integral conversion. but this is obviously not true, as signed byte can hold such value. Check your math... the most negative number a signed byte can hold is -127. The

Re: possible bug in std.conv.parse

2014-04-26 Thread Adam D. Ruppe via Digitalmars-d
On Saturday, 26 April 2014 at 23:43:11 UTC, Adam D. Ruppe wrote: Check your math sorry, i should check my own math. I got it backwards, you're right.

Re: possible bug in std.conv.parse

2014-04-26 Thread Timon Gehr via Digitalmars-d
On 04/27/2014 01:43 AM, Adam D. Ruppe wrote: On Saturday, 26 April 2014 at 23:36:28 UTC, ketmar wrote: this code: std.conv.parse!byte(-128) throws error: Overflow in integral conversion. but this is obviously not true, as signed byte can hold such value. Check your math... the most negative

Re: possible bug in std.conv.parse

2014-04-26 Thread ketmar via Digitalmars-d
ah, sorry, this is my own fault, there is no bug in parser. what i'm doing is parse!byte(128) and then negating the result. silly me.

Re: possible bug in std.conv.parse

2014-04-26 Thread Andrei Alexandrescu via Digitalmars-d
On 4/26/14, 4:43 PM, Adam D. Ruppe wrote: On Saturday, 26 April 2014 at 23:36:28 UTC, ketmar wrote: this code: std.conv.parse!byte(-128) throws error: Overflow in integral conversion. but this is obviously not true, as signed byte can hold such value. Check your math... the most negative

Re: possible bug in std.conv.parse

2014-04-26 Thread Andrei Alexandrescu via Digitalmars-d
On 4/26/14, 4:36 PM, ketmar wrote: this code: std.conv.parse!byte(-128) throws error: Overflow in integral conversion. but this is obviously not true, as signed byte can hold such value. the question is: is it bug, or it's intended behavior to limit signed integrals to values which can be

Re: possible bug in std.conv.parse

2014-04-26 Thread Adam D. Ruppe via Digitalmars-d
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 1000 was 128, but it is actually -128 in twos

Re: possible bug in std.conv.parse

2014-04-26 Thread ketmar via Digitalmars-d
On Sunday, 27 April 2014 at 00:04:15 UTC, ketmar wrote: but this is definetely bug, i think: void main() { import std.stdio : writeln; import std.conv : to; writeln(to!int(29a, 16)); // 666 writeln(to!int(+29a, 16)); // Unexpected '+' when converting from type string base 16 to type int

Re: possible bug in std.conv.parse

2014-04-26 Thread ketmar via Digitalmars-d
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