Welcome, Guest. Please login or register.

Author Topic: Decimal Floating Point and Abstraction Layer  (Read 4531 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline olsen

Re: Decimal Floating Point and Abstraction Layer
« on: March 23, 2016, 03:04:39 PM »
Quote from: tonyd;806229
Planning to try OS4.1FE Classic with UAE shortly....
Forgive me if they already have this....
Just curious: which application do you have in mind for decimal floating point numbers?

I recall that this format is useful for storing "human-readable" numbers, such as for prices and for performing simple arithmetic operations on these (add, subtract, divide, multiply). Beyond that, the IEEE 754 format allows you to keep errors much better in check.

But it's sometimes difficult to explain to the end-user why the numbers that tumble out of supposedly simple calculations don't seem to add up if IEEE 754 format is being used.
 

Offline olsen

Re: Not "Lossy" -- Re: Decimal Floating Point and Abstraction Layer
« Reply #1 on: March 24, 2016, 03:34:49 PM »
Quote from: JJ;806287
I will admit that I do not seem to have the deep knowledge you have on this subject, but this statement confuses me ?
You are in good company in this respect. It is puzzling, but nevertheless true as far as the part of a floating point number is concerned which follows the decimal point.

Numbers such as 1234.5 can be written down as a series of digits, each multiplied by a power of ten, e.g. 1 * 10^3 + 2 * 10^2 +  3 * 10^1 + 4 * 10^0 + 5 * 10^(-1). But this is not how floating point numbers are represented by the computer. Instead of powers of ten it uses powers of two.

Simplifying things for the sake of this example (there are other rules which apply to floating point numbers which are not quickly explained): it means that you have to rewrite those sums above like so: 1234.5 = 1 * 2^10 + 1 * 2^7 + 1 * 2^6 + 1 * 2^4 + 1 * 2^1 + 1 * 2^(-1)

That works well because you can write 0.5 as 2^(-1) = 1/2. But what do you do with a number such as 0.1? You would have to write 0.1 as a sum of powers of two, which doesn't work out neatly. The best you can do is come up with a sum that's an approximation of 0.1, which is either a bit larger or smaller than 0.1, but not exactly the same value (please don't ask me to come up with such a sum, I can't do this off the cuff).

This is what makes floating point numbers very unwieldy when you want to provide exact decimal number figures to users. There will invariably be "roundoff" errors which are very hard to explain. If you learned arithmetics at school you will calculate using the powers of ten sums implicit in how you write down numbers. Binary numbers are at best an oddity, and floating point numbers are an oddity on top of an oddity.

In the end you get complaints that "numbers don't add up", there's a tenth of a cent missing from a compound sum, etc. when those numbers are indeed sufficiently accurate for calculations, but converting them into a displayable form introduces visible rounding errors.