Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.conv: to and parse dont work correct with negative numbers #9785

Open
dlangBugzillaToGithub opened this issue Dec 16, 2019 · 0 comments
Open

Comments

@dlangBugzillaToGithub
Copy link

bugzilla (@berni44) reported this on 2019-12-16T16:23:56Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=20452

Description

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
}
---
@LightBender LightBender removed the P3 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants