www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4122] New: More handy BigInt.toString()

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4122

           Summary: More handy BigInt.toString()
           Product: D
           Version: future
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



The toString() of BigInt is not handy to print bigintegers during debugging. I
have had to create a function like:

const(char)[] bigIntRepr(BigInt i) {
    const(char)[] result;
    i.toString((const(char)[] s){ result = s; }, "d");
    return result;
}


Note that this doesn't work (Access violation, I don't know why):

const(char)[] bigIntRepr(BigInt i) {
    const(char)[] result;
    i.toString((const(char)[] s){ result = s; }, null);
    return result;
}


My suggestion is to change the signature of BigInt.toString() from this:

void toString(void delegate(const (char)[]) sink, string formatString) const {


To something like this:

string toString(void delegate(string) sink=null, string formatString="d") const
{   

And make it return a string filled with the decimal representation when sink is
null; and to return an empty string when sink!=null.

------------------------

Eventually the signature can even become:

string toString(void delegate(string) sink=null, string formatString="d",
string thousands="") const {

So if thousands="_" the number gets represented as:

"100_000_000_000"

But this is less important.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 24 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4122




See:
http://www.dsource.org/projects/phobos/changeset/2183

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 19 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4122


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |FIXED



Marking this as fixed, since you can just use writefln() in 2.051 and later.
(as added in the changeset).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 18 2011