[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Result not zero
David T. Ashley
RE: Result not zero
Sat, 1 Sep 2001 20:38:27 -0400
Well, Kevin's reply brings up another weird and off-topic point, which is
if the rules for financial numbers are clear and regulated by law, then
somebody ought to create a software module that implements all that
functionality and sits on top of the GMP ...
Still, in good humor, I honestly don't think the GMP is the right solution
for financial matters because the amount of money one can have is limited.
Even Microsoft Excel doesn't allow infinite amounts of money, and you know
there are weenies in Washington using Excel to do rough budget calculations
for the U.S. and for world money supplies. GMP will certainly work, but it
is a matter of efficiency.
Bill Gates at the last count I remember had about 50 billion dollars, which
is 5E12 pennies, or about 42 bits of pennies. Allowing for inflation, and
for a bunch of other stuff, I think that allowing 256 bytes (2048 bits) per
integer should meet anyone's needs. That is about 1E616 pennies. That
should be enough. So I would say don't use the GMP because of the potential
allocation slowness--invent a fixed-size integer library where everything
gets 2048 bits.
Should work until the next Microsoft ...
> -----Original Message-----
> From: address@hidden [mailto:address@hidden Behalf Of
> Kevin Ryde
> Sent: Saturday, September 01, 2001 8:18 PM
> To: Michael Mann
> Cc: address@hidden
> Subject: Re: Result not zero
> "Michael Mann" <address@hidden> writes:
> > I was looking at GMP to alleviate some situations where ieee floating
> > point's inherent problems are unacceptable, accountancy for
> example. That
> > is, certain decimal numbers can't be represented correctly in
> ieee--a BCD
> > number class is required.
> It's unlikely mpf will suit, it guarantees even less than ieee.
> > Here's my sample code: subtract 0.01 from .1, 10 times. You
> should have zero
> > at the end. However, the result claims to be 0.1469367938527859385e-37.
> mpf uses binary internally, and decimal fractions like .1 and 0.01
> can't be exactly represented, hence the rounding.
> > Is there a fix for this? Am I using the right mp?_ functions? Is the GMP
> > library appropriate?
> As others have pointed out, mpz might be better, if you can work in
> cents or hundredths of cents or whatever your business rules require.
> Bug-gmp mailing list