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