[Issue 4122] New: More handy BigInt.toString()
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Apr 24 16:09:04 PDT 2010
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 at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2010-04-24 16:09:02 PDT ---
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: -------
More information about the Digitalmars-d-bugs
mailing list