Issue 20452 - std.conv: to and parse dont work correct with negative numbers
Summary: std.conv: to and parse dont work correct with negative numbers
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-16 16:23 UTC by berni44
Modified: 2024-12-01 16:36 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description berni44 2019-12-16 16:23:56 UTC
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
}
---
Comment 1 dlangBugzillaToGithub 2024-12-01 16:36:06 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9785

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB