www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13033] New: std.conv.toBase too

https://issues.dlang.org/show_bug.cgi?id=13033

          Issue ID: 13033
           Summary: std.conv.toBase too
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: bearophile_hugs eml.cc

In Phobos there is a function to convert from a string representing a number in
any small base to an integral number:

void main() {
    import std.stdio, std.conv;
    "00101201102".to!int(3).writeln; // Prints: 7814
}



This is not supported:

void main() {
    import std.stdio, std.conv;
    101201102.to!int(3).writeln;
}


But it's easy to work around it:

void main() {
    import std.stdio, std.conv;
    101201102.text.to!int(3).writeln; // Prints: 7814
}


But a rather common operation is to convert to arbitrary small base. I'd like a
handy function like this in Phobos:

void main() {
    import std.stdio, std.conv;
    7814.toBase(3).writeln; // Should print: 101201102
}

--
Jul 03 2014