jans@tekgvs.GVS.TEK.COM (Jan Steinman) (07/19/88)
<jfh@rpp386.UUCP (The Beach Bum):>
<<wcs@skep2.UUCP (46323-Bill.Stewart.[ho95c],2G218,x0705,):>>
<<<georg@unido.UUCP (Georg A. M. Heeg):>>>
<<<As basic technology we need decimal fixed point arithmetic. The fiscal
office certainly does not accept rounding errors through floating point
arithmetic...>>>
<<Surprise! You'll get roundoff errors just as badly in fixed decimal..>>
I think Georg's use of "rounding errors" is a misnomer. Floating point is
unacceptable for business applications due to "drop-off errors", where
significant digits are actually lost in accumulation (+-) math.
<The division of two integers yields an object of class Fraction, which is
simply a representation of the division as a "reduced" fraction...>
(Thanks for the great lead in, Bart!) A few years ago, I implemented
fixed-point in Smalltalk, as a subclass of Fraction. (I'd post the code, but I
can't find it just now.) It worked fine for everything but #printOn: -- after
hours of crawling through Knuth, I couldn't find a simple way to do the
generalized case of representing fixed point numbers with arbitrary deltas,
except for coercing the whole thing to Float. If you are only interested in
deltas that are powers of ten, the problem of representation is vastly
simplified! :-)
By subclassing Fraction, the problem is essentially reduced to producing the
proper conversion methods, such that $123.45 is stored as 12345/100, etc. Math
methods are all inherited, and maintain (for practical purposes) infinite
precision. (Well, until the damn things get so big that paging makes it
impractical.)
Smalltalk is a language that even Carl Sagan ("billions and billions") could
get along with!
:::::: Software Productivity Technologies -- Experiment Manager Project ::::::
:::::: Jan Steinman N7JDB Box 500, MS 50-383 (w)503/627-5881 ::::::
:::::: jans@tekcrl.TEK.COM Beaverton, OR 97077 (h)503/657-7703 ::::::