Bug 4122 – More handy BigInt.toString()

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-04-24T16:09:00Z
Last change time
2015-06-09T05:13:45Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-04-24T16:09:02Z
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.
Comment #1 by bearophile_hugs — 2010-11-19T10:06:24Z
Comment #2 by clugdbug — 2011-03-18T23:33:50Z
Marking this as fixed, since you can just use writefln() in 2.051 and later. (as added in the changeset).