Dik said:
What of the system is broken?
The current Turkish Lira would do pretty well. The previous one would
be bad, especially if you want to keep up to figures until the nearest
Kuru. But when somebody complains that there is a difference of one
cent in the result, that only means that the calculations are done
using the wrong data type. If you expect that anybody in Turkey before
the introduction of the new Lira bothered about anything less than
25000 Lira, you are wrong. (I still remember the 10,000,000 Lira tip
for the waiter after a small lunch for four.)
No financial program can cope with hyperinflation when it does not
regularly adjust to the inputs. You should know the smallest amount
that legally can be distinguished and base your calculations on that;
using integers. Picking the Turkish Lira is a red herring. You
could equally well have picked the Hungarian Pengo from just after
the war. If I have it right, at some moment they had notes of
1,000,000,000,000,000,000,000,000 Pengo. Or the Zimbabwian dollar
notes that have printed on them an ultimate date of validity (which
is not more than six months after introduction).
The whole point is that in most financial transactions it is precisely
defined how fractions of something should be rounded. Any attempt to
be slightly imprecise (using floating point) will fail at some point
or another.
No. The question is not whether the imprecise answer is the
correct answer (this is highly unlikely), but whether
the correct answer can be determined from the
imprecise answer.
You have to find out what the correct answer is and calculate
that. It is unlikely to be the native answer, whether calculated
using integer or floating point. The fundamental questions are:
i: can you determine the correct answer from
the calculations done using your chosen data type
ii how difficult is it to determine the correct answer.
For i there is no clear advantage to integer calculations (though it
is clear that there are native floating point type and native integer
types that do not satisfy i).
For ii, there may be small advantage to integer calculations, but
given that calculations with non-integer results (e.g. compound
interest) are needed, this advantage is, at best, quite small.
I would advocate making any system flexible and fault tolerant.
In this case it means taking input in many forms and doing
the same thing if the input is
1 cent
1.000001 cents
0.999999 cents
(yes this means that calculations with Turkish Lira are not
exact to the lira) and failing gracefully when the numbers
become large.
On the balance, I would expect a floating point approach
to be preferable, but double, while carrying any needed
practical precision, may not have the precision needed to
obtain the correct accounting answer. [Note the question
is not, "do native calculations give the accounting answer",
they do not. The question is "Can the accounting answer
be determined from the native calculations?"]
- William Hughes