kenji hara Wrote:

> 2011/8/31 Jonathan M Davis <jmdavisp...@gmx.com>:
> > Unfortunately however, the proposal seems to have gone nowhere thus far. 
> > Until
> > it does, pretty much every object is just going to use toString without
> > parameters, and the problems with BigInt's toString remain. However, if the
> > proposal actually gets implemented, then the issue should then be able to be
> > sorted out. Objects would have writeTo and toString would presumably be
> > deprecated.
> 
> I have posted pull request to fix BigInt's formatting with writef(ln)
> <- formattedWrite().
> https://github.com/D-Programming-Language/phobos/pull/230
> 
> Kenji Hara

There are problems with opCmp as well. The "<" and ">" operators won't compile 
if either argument is a const BigInt, so a lot of otherwise unnecessary copying 
is required.

You can see this in these functions I've had to add the following functions to 
my BigDecimal package:

private BigInt abs(const BigInt num) {
    BigInt big = copy(num);
    return big < BigInt(0) ? -big : big;
}

private BigInt copy(const BigInt num) {
    BigInt big = cast(BigInt)num;
    return big;
}

private int sgn(const BigInt num) {
    BigInt zero = BigInt(0);
    BigInt big = copy(num);
    if (big < zero) return -1;
    if (big < zero) return 1;
    return 0;
}

(I'd be happy to learn there's a better way to implement these.)

Paul


Reply via email to