Given are 5 REAL4 numbers, organized in an array. There are 6 arrays with the same elements, but in different element order:

A = (1e20,17.0,-10.0,130.0,-1e20)

B = (1e20,-10.0,130.0,-1e20,17.0)

C = (1e20,17.0,-1e20,-10.0,130.0)

D = (1e20,-10.0,-1e20,130.0,17.0)

E = (1e20,-1e20,17.0,-10.0,130.0)

F = (1e20,17.0,130.0,-1e20,-10.0)

The task is: add the array elements and calculate the array sum. For that easy example, we don't need a computer or a pocket calculator; a bit mental arithmetic leads to 137 as the right result. Please note also that no number has a fractional part, so classical rounding errors can't occur. Nevertheless, the entire floating point calculation with REAL4, REAL8, or REAL10 values will crash and produce garbage.

I've realized the floating point calculation with the FPU under PowerBASIC 3.5 (the DOS compiler). But it should also compile with PB 3.0. It's simple 16 bit real mode code; therefore I did the upload in the 16 bit sub-forum and not in the PB forum.

The left column of the screen shot above shows the classic floating point results. Only the sum of array E is correct; the rest is junk. The reason for the calculation crash is the special data constellation. I've dozens of such ill conditioned examples; a normal naive floating point computation would fail in any case.

The right column shows the right results with the extra long dot product accumulator. The software is at this point in experimental stage, nothing is finished or fixed. The basic idea comes from the old desk calculators, for example the model MONROMATIC ASMD from 1956 produced by Monroe Calculating Machine Company, New Jersey, USA.

This desk calculator did addition, subtraction, multiplication, division and the accumulation of partial results in a long accumulator. In other words: high-accuracy arithmetic.

I'm using now REAL4 numbers and nothing else - no higher precision, no BCD arithmetic, no big number library etc. But for the multiplication the software uses a long accumulator of 48 bits for the product mantissa. For details of the REAL4 data layout, please check Raymond Filiatreault's excellent site:

http://www.website.masmforum.com/tutorials/fptute/. Thank you, Raymond. The addition results are accumulated in the dot product accumulator with a length of (theoretical) 556 bits. For design reasons my accumulator is 576 bits long (72 bytes). So, there are 20 bits (2.5 bytes) for temporary overflows at the top. Furthermore, there are 3 extra bytes at the tail for the handling of underflows.

I did the same thing 30 years ago; I've found my old Z80 sources. I used this algorithms and converted the code to the 8086 platform for usage with PowerBASIC. With a lot bit witchcraft and many debugging sessions: that's the result. The software calculates sums and the dot product in high accuracy - at the moment only for REAL4 values. It handles underflows and overflows properly. It has several rounding methods: round to nearest, round to infinity, round up, round down, and intervall rounding - that's for intervall mathematics.

At the moment I'm developing a 64 bit version. I think that's the future and one has larger and more registers. That's more comfortable. If this is done, the 32 bit version will follow.

Please don't download capture.zip and monroe.zip; these are only the images above. The software archive for download is exact.zip.

Gunther