[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Result not zero
From: |
Kevin Ryde |
Subject: |
Re: Result not zero |
Date: |
02 Sep 2001 10:18:07 +1000 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.5 |
"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.