a decimal class for Squeak?

Bruce Cohen cohenb at gemstone.com
Wed Jan 6 19:07:45 UTC 1999


Jan Bottorff writes:
>> The round off rules, AT THE TIME OF CALCULATION, are very important to
>> maintaining consistent results. Taking intermediate results to some
>> calculation, and reducing their precision (rounding) for output will cause
>> the output value of later steps in the calculation to be different. The
>> results of every calculation need to be rounded to some defined precision,
>> with some possible optimizations (like if you add two decimal numbers with
>> two decimal digits, you don't need to round the result to two decimal).
>> Multiplying and dividing are among the operations than need the precision
>> evaluated after every operation.

This is why the IEEE 754 standard supports gradual under/overflow, and
an extended precision (80-bit) format for intermediate results.
Regrettably, support for these features is either missing or incomplete
in many implementations.

>> A big advantage I see of using scaled integers or fractions is you don't
>> loose precision when the numbers get really big. FP numbers don't give any
>> warning when the mantissa starts to loose precision. Maintaining exactly
>> accurate fractional representation may not be the goal. Consistency of how
>> the numbers interact and are output and stored is.

In general, I agree that floating point is not well suited to this type
of computation, since it rarely can give you guarantees about when and
how precision *will* be lost (and, as mentioned above, it is often
difficult even to tell when it *has* been lost).

Another alternative might be using exact fractions implemented with lazy
precision extension.  This is currently a hot topic in functional
programming; there are several papers on it in the latest proceedings of
the SIGPLAN Functional Programming conference.  If anyone's interested, I
can round up some citations tonight; I left the book at home.
-----------------------------------------------------------------------------
"... Profits, like sausages ... are esteemed most by those who know least
about what goes into them." - Alvin Toffler
-----------------------------------------------------------------------------
Bruce Cohen,                               |  email: cohenb at gemstone.com
GemStone Systems, Inc.                     |  phone: (503)533-3602
20575 NW Von Neumann Drive                 |  fax:   (503)629-8556
Beaverton, OR USA 97006                    |  web:   http://www.gemstone.com





More information about the Squeak-dev mailing list