Welcome, Guest. Please login or register.

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

Description:

0 Members and 1 Guest are viewing this topic.

Offline psxphill

Re: Decimal Floating Point and Abstraction Layer
« on: March 23, 2016, 06:47:42 PM »
Quote from: olsen;806245
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.

If you are writing financial software and use floating point numbers then instead of wasting time explaining to the end-user why none of the figures add up right, you should invest the time in something more beneficial to society like brushing up your cv and looking for a job that doesn't require things to add up right. Staying in the job would be immoral.

Floating point is a lossy compression algorithm. If end users buy the explanation then they shouldn't be doing that job either.
« Last Edit: March 23, 2016, 06:51:14 PM by psxphill »
 

Offline psxphill

Re: Not "Lossy" -- Re: Decimal Floating Point and Abstraction Layer
« Reply #1 on: March 24, 2016, 09:44:06 AM »
Quote from: Thomas Richter;806274
The reason why decimal is used for banking is because it can represent decimal fractions (as used by Humans) precisely, but that's a rather arbitrary choice. As soon as you need to calculcate interest rates and the like, both formats generate loss, necesarily.

Russia had the first decimal currency in 1704, the UK switched in 1971. It's not an arbitrary choice.

Obviously if you are calculating a percentage of 0.01 then you cannot represent that as money as there are no fractions of a penny. That isn't lossy as you aren't losing anything that could be represented by real money.

Floating point on the other hand cannot represent decimal currency at all. It is impossible to store most 2 digit decimal numbers accurately in a floating point number. All you can do is store the closest number and then round it when displaying it. However this causes a problem when you do something as mundane as adding two numbers together.

You are right that you can't represent 1/3 in decimal, but that isn't a problem at all for accountants. Not being able to add 0.10 & 0.10 and get 0.20 is. caveat: I don't know if this is a real example, but there are situations where two trivial values cannot be added up as I was once given the task of fixing a system using floating point. I replaced it with 64 bit integer maths (on a z80 without a 64 bit maths package).

I hope you're not trying to justify using floating point for financial calculations as that would be worrying.