Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mstan!amull From: amull@Morgan.COM (Andrew P. Mullhaupt) Newsgroups: comp.lang.c Subject: Re: Floating point exactness & alternatives (summary) Summary: It ain't necessarily so... Message-ID: <1454@s8.Morgan.COM> Date: 11 Aug 90 03:06:46 GMT References: <713@tetrauk.UUCP> <1990Aug7.173030.2823@zoo.toronto.edu> <1990Aug9.154302.29976@zoo.toronto.edu> Organization: Morgan Stanley & Co. NY, NY Lines: 42 In article <1990Aug9.154302.29976@zoo.toronto.edu>, henry@zoo.toronto.edu (Henry Spencer) writes: > In article <168@srchtec.UUCP> johnb@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