This math scares me
Grant Edwards
grante at visi.com
Thu Mar 15 13:04:24 EST 2001
In article <98qv55$f5d$1 at news.udel.edu>, Terry Reedy wrote:
>So, .1% gets represented as the binary equivalent of, perhaps,
>.0010000000000000001.
>So the interest on 2,000,000,000 pennies is calculated as
>2000000.0000000002 instead of
>2000000 pennies. When rounded off, they are the same. To me, this is, as
>I claimed. 'well enough' (for many purposes, at least), even though not
>'exact'.
If that's good enough for you, then go ahead and use FP.
But, the people who actually write financial SW for a living
seem to think it's not good enough. You would have to talk to
one of them to find out the exact situations where FP proved
insufficient. But, I don't think anybody would have gone to
the trouble of implimenting BCD math just for the fun of it.
OTOH, I guess I know people who would do stuff like that just
for fun.
I do remember that BCD math was a big selling point of many
compilers.
>Now suppose a financial instrument carries a yearly interest rate of .077
>(7.7%) with montly payments. Then the monthly multiplier is
>.0006416666666666666666666666666666666666...
>Whoops, the BCD representation has to be approximate also, just like the
>binary one.
>Even if a monthly multiplier like .00643 (corresponding to a
>yearly 7.716%) is exactly represented in BCD, there may still
>be fractional amounts that need to be rounded to the nearest
>penny by one rule or another. BCD does not eliminate the
>problems of finite precision arithmetic.
Probably not. But it apparently makes the problems easier in
the financial world.
--
Grant Edwards grante Yow! The FALAFEL SANDWICH
at lands on my HEAD and I
visi.com become a VEGETARIAN...
More information about the Python-list
mailing list