Decimal arithmetic, was Re: Python GUI app to impress the boss?

Paul Rubin phr-n2002b at NOSPAMnightsong.com
Fri Sep 20 20:33:46 EDT 2002


Christopher Browne <cbbrowne at acm.org> writes:
> The COBOL (or PL/I, or anyone else accustomed to BCD data types) guy
> will justifiably look at the bizarro FP rounding as being, well,
> bizarre.
> 
> There's _no_ good reason for subtracting two perfectly good decimal
> values from one another to result in having weird artifacts appear in
> some 17th decimal place, aside from having a willingness to admit
> fairly deranged arithmetic.

Um, put $1000.00 in an imagined bank account and have it collect 5%
annual interest, compounded daily for 25 years.  How much money is in
the account at the end?

The "true" answer is (1+(.05/365))**(365*25) dollars, assuming 365 day
years.

The IEEE double precision answer will be extremely close to that
amount.

What happens if you do that calculation in BCD?  How would you even
specify how to do it?  I don't think you will get nearly as much
accuracy.



More information about the Python-list mailing list