Kevin Bealer wrote:
1. To solve the basic problem the original poster was asking -- if you are 
working
with simple decimals and arithmetic you can get completely accurate 
representations
this way.  For some cases like simple financial work this might work really 
well.
e.g. where float would not be because of the slow leak of information with each
operation.  (I assume real professional financial work is already done using a
(better) representation.)

A reasonable way to do financial work is to use longs to represent pennies. After all, you don't have fractional cents in your accounts.

Using floating point to represent money is a disaster in the making.


2. To explain why the 'simple' task of representing something like .1 wasn't as 
easy
as it looks.  In other words, why the people who designed float weren't just 
brain
dead.  I think they really knew what they were doing but it shocks most people 
at
first that a modern computer can't do what they see as grade school arithmetic.

There's just no getting around needing to understand how computer arithmetic 
works.


I think for some purposes though, lossless domain specific representations can
be a good tool -- if you can represent a problem in a way that is lossless you 
can
maybe do better calculations over long series than working with 'double' and 
taking
the accuracy hit.  This is necessarily an application specific technique though.

I.e. you have to know what you're doing :-)

Reply via email to