Re: float decimal



Michel Hack wrote:
Terje Mathisen wrote:
|> I have yet to see anything even remotely time-critical enough to
require |> hw decimal fp, instead of simply using either an upfront
conversion to |> binary, or a sw lib that computes directly in ascii.

The first is what gets many into trouble, and the second really is
slow.

By first I assume you meant conversion to binary, i.e. the current default: Yes, lots and lots of programmer (myself included a few times) have messed this up, but as soon as you realize that there are some rules you have to obey, it does work.

Re ascii (or bcd) really slow: Do you have a pointer to some sample problems that are both important and time-critical?

> Proper use of scaled-integer arithmetic works, for professionals.

My (and I'm guessing Nick's) claim is that it is the _only_ thing that works. To make it more accessible you could pack these scaled integers into an object with a 64-bit scale and a 64-bit mantissa, then defining arithmetic operations with either explicit or implicit (for operator +-*/) rounding behavior.

My guess is that this would almost certainly be about as fast as the 754R HW FP support, and with much less hidden problems.

> It is hoped that DFP will bring this to a larger
programming community.

I agree with Nick's warning however that the elimination of gross
errors may lead to more pernicious subtle errors -- but that's not new.

(Financial calculations involving interest rates and amortisations
may stretch the scaled-integer approach, as math library functions
are involved -- but there tend not to be legally-defined decimal rules
as there are for currency conversions and plain interest or tax
arithmetic, as far as I know. Our French colleagues are working on
correctly-rounding versions of such library routines, and are aware of
DFP.)

When doing financial modeling binary fp is both fast and accurate, as you note tax/interest/legal stuff needs to be calculated according to explicit rules anyway.

The fun part here is that it is relatively easy to get legally-correct results when doing single calculations in binary fp. :-)

Terje

--
- <Terje.Mathisen@xxxxxxxxxxxxx>
"almost all programming can be viewed as an exercise in caching"
.