[Issue 20452] New: std.conv: to and parse dont work correct with negative numbers
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Dec 16 16:23:56 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=20452
Issue ID: 20452
Summary: std.conv: to and parse dont work correct with negative
numbers
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: bugzilla at d-ecke.de
When the radix is not 10 the conversion from and to int does produce wrong
results for negative numbers
---
import std.stdio;
import std.conv;
void main()
{
foreach (i;2..17)
writeln(to!string(-1, i));
}
---
produces
---
11111111111111111111111111111111
102002022201221111210
3333333333333333
32244002423140
1550104015503
211301422353
37777777777
12068657453
-1
1904440553
9BA461593
535A79888
2CA5B7463
1A20DCD80
FFFFFFFF
---
The same for the conversion from string to int:
---
import std.stdio;
import std.conv;
void main()
{
writeln(to!int("-1", 10)); // works
writeln(to!int("-1", 11)); // ConvException
}
---
--
More information about the Digitalmars-d-bugs
mailing list