Bug 20452 – std.conv: to and parse dont work correct with negative numbers

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-12-16T16:23:56Z
Last change time
2024-12-01T16:36:06Z
Assigned to
No Owner
Creator
berni44
Moved to GitHub: phobos#9785 →

Comments

Comment #0 by bugzilla — 2019-12-16T16:23:56Z
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 by robert.schadek — 2024-12-01T16:36:06Z
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