Floating point exactness & alternatives (summary)

Andrew P. Mullhaupt amull at Morgan.COM
Sat Aug 11 13:06:46 AEST 1990


In article <1990Aug9.154302.29976 at zoo.toronto.edu>, henry at zoo.toronto.edu (Henry Spencer) writes:
> In article <168 at srchtec.UUCP> johnb at srchtec.UUCP (John Baldwin) writes:
> 
> If you are doing tricky things with exchange rates, all bets are off. :-)
> ... So if you're trying
> to keep track of that transaction by program, you don't need to keep the
> mathematically-exact amount, which is wrong anyway; it is both sufficient
> and correct to use the appropriate rounding function to give an integer,
> and store that.

If you are marking the resultant of the transaction to market, you
_do_ need to have the fraction. 

One of the most interesting difficulties in an "all-integer" or
single precision financial package is split adjustment of stocks.
I know directly of a case where due to a one-bit error in single
precision rounding, a portfolio was found to be unhedged by a
single share. The trading system in question was capable of ordering
a trade to rebalance, and it did so. It turns out to be extremely
unusual for such a trade to be generated for any really useful
purpose, and so the traders operating the system noticed this
trade, and became concerned that a potentially serious error was
going undetected. After some effort, the source of the error was
found, and (somewhat sheepishly) a second trade of a single share
had to be ordered to reverse the effect of the first. Now it's
kind of funny that a single share trade happens, and maybe the
financial loss is at most 25 cents capital and some unmentionable
transaction cost, but the hassle for the traders is not ignorable.

There is another case I know of where tens of thousands of shares 
went round-trip but this was a combination of a database error and
floating point mishap. 

The moral of the story? Do not make casual assumptions about the
kind of arithmetic required in business applications. Expect that
"getting it right to the penny", or any other fixed accuracy will
not be enough in every situation. There will always be one more
example than you can think of when you're trying to get away with
a low ceiling in a financial application. 

Later,
Andrew Mullhaupt



More information about the Comp.lang.c mailing list