www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20452] New: std.conv: to and parse dont work correct with

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 puremagic.com
          Reporter: bugzilla 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
}
---

--
Dec 16 2019