Re: why still use C?

From: Mike Cowlishaw (mfcowli_at_attglobal.net)
Date: 11/22/03


Date: 21 Nov 2003 23:48:45 GMT

Morris Dovey wrote:
>>> The need for high degrees of precision in computation is not a
>>> new issue and I fail to see how a change in radix will provide a
>>> major improvement.
>> It's not "high degrees of precision" that are needed. It's a
>> fairly low degree of precision, but it needs to be provided
>> exactly, which makes is similar in some ways to requiring
>> infinite precision.
> I'm going to have to think about this statement for a while. I'm
> mulling over simple arithmatic operations like 1/3, 1/7, etc.;
> and asking myself: "What's improved by performing this operation
> in FP-10?" Am I grossly missing the point?

Perhaps so. Even with those divisions base 10 helps a little,
because the result you get will always be the same as a 'manual'
calculation of the same operation.

But the real benefits are where the results are expected to be
exact, or certain rounding rules must be strictly applied.
See the section 'What problems are caused by using binary floating-point?'
in: http://www2.hursley.ibm.com/decimal/decifaq.html

>>> Would anyone care to wager that "the typical billing program"
>>> /cannot/ be improved by overall factors in excess of three even
>>> if decimal floating point is not provided?
>>
>> It's not an issue where improvement can be measured in terms of "[a]
>> factor in excess of three". The key point is that the financial
>> community has a commonly occuring need for the numbers, as printed
>> with a fixed number of decimal places, to add up exactly to the
>> specified total printed with the same number of decimal places,
>> without roundoff error. In general that will happen only when using
>> a radix that is a power of 10. One solution is to use scaled
>> integers, such that an integer such as 3412 represents a value of
>> 34.12. However, use of scaled integers complicates programs; a
>> common problem is forgetting to apply the scale factor, or applying
>> it inappropriately.
>
> I guess I should have put a smiley on that statement - but I'd
> like to respond seriously to your serious response. When PHLX
> (The Philadelphia Stock Exchange) switched from fractional prices
> to decimal prices in 2000, they switched from scaled integers to
> binary floating point. The difficulties you present were examined
> and efficient solutions implemented. It was a highly educational
> process for all involved since we nearly all "knew" (at the
> beginning) that floating point wasn't any good for monetary
> values. My discovery was that the problem didn't lie with the
> hardware or the format - it lay with the uninformed prejudice of
> programmers.

It is indeed possible, with great care and skilled error analysis, to
use binary floating point for some financial applications (especially
those where no calculation takes place .. numbers are just moved
around). But it is hard and unnecessarily complicated -- and as
soon as the application is modified or maintained, 'accidents' are
just waiting to happen. It's faster (given the hardware), simpler,
and easier to use base-10 arithmetic.

> Never wanting to miss an opportunity to display my considerable
> ignorance, why not leave selection of floating point radix a
> compile/link option? I've been thinking back over all the
> financial code I've ever written/seen and can't think of any
> instance where use of more than a single floating point radix
> made any sense at all. Why not simply use the type names we
> already have?

This would mean that one could never have both binary and decimal
FP data in the same program/structure. A pragma which could be used
inside a program would be especially dangerous (consider the
base being switched inside an #include). The entire existing base
of binary FP functions could not be used from a program which
selected base 10.

Mike Cowlishaw
Google: decimal arithmetic

-- 
comp.lang.c.moderated - moderation address: clcm@plethora.net


Relevant Pages

  • Re: Motorized knee" on the mill works great now!
    ... I consider it (extra precision in registers) a bug, ... claimed the hardware got wrong. ... For floating point, it allows one to sum a large number of ...
    (rec.crafts.metalworking)
  • Re: why still use C?
    ... It's not "high degrees of precision" that are needed. ... A great many programs make no use of floating point at all, ... In general that will happen only when using a radix that is a ... > language definition? ...
    (comp.lang.c)
  • Re: Fixed point Vs Floating point
    ... Is this how the hardware design is done? ... Floating point has more dynamic range for the given number of bits ... requirements but doesn care as much about the precision. ... fitting fixed-point math to the algorithm is simple, ...
    (sci.electronics.design)
  • Re: Precision
    ... Whether one does the subsequent calculations in internal ie integer format ... I have always used external format with Precision 4 since my ... floating point calcs which are done in binary have around 3% error albeit at ... positions it is IMPOSIBLE to have a result of 4 decimals with the 2 ...
    (comp.databases.pick)
  • Re: Linear Algebra Challenge
    ... Since I'm using floating point, so I'll never be able to calculate one ... floating point math set to 99 digits. ... As close as I'm willing to wait if I use arbitrary precision. ... This mode is fast; when you select arbitry ...
    (comp.sys.hp48)