comp.lang.ada
 help / color / mirror / Atom feed
From: fred@genesis.demon.co.uk (Lawrence Kirby)
Subject: Re: The disturbing myth of Eiffel portability
Date: 1996/11/24
Date: 1996-11-24T00:00:00+00:00	[thread overview]
Message-ID: <848871509snz@genesis.demon.co.uk> (raw)
In-Reply-To: E17FM8.9Gs@thomsoft.com


In article <E17FM8.9Gs@thomsoft.com> kst@thomsoft.com "Keith Thompson" writes:

>In <dewar.848444338@merv> dewar@merv.cs.nyu.edu (Robert Dewar) writes:
>> Kaz says
>> 
>> > Any computer scientist worth his salt knows that floating point
>> > numbers are only approximations of real quantities. Well written
>> > numerical analysis code takes this into consideration, and can be
>> > made portable.
>[...]
>> Many computer scientists have this view of floating-point, but at least in
>> the IEEE world, this is an incorrect view. IEEE arithmetic is NOT an
>> approximation of real arithmetic, but rather an EXACT implementation of
>> a very well defined arithmetic, whose axioms are well understood. 
>
>True, but that well defined arithmetic was designed to be an approximation
>of real arithmetic.

I observe that there are a lot of 32 bit integer + IEEE floating point
platforms out there so what is the best way to implement financial
calculations (being the topic of this thread) on such platforms? 

If you represent quantities as integral values that can be represented
exactly by IEEE then you have something has a larger guaranteed range of
values than a 32 bit integer (e.g. what long often in on C implementations)
and results are exact so long as they too are representable. Division can
be dealt with without too much difficulty. Many CPUs now can process
floating point operations (especially mutiplication) faster than they can
process integer operations.

Financial calculations within (fairly generous) limits can use IEEE
floating point and be *proven* correct barring bugs in the implementation.
But bugs can affect integer calculations as well. All this depends on the
type of operation being performed. Adding up the value of a portfolio has
different issues compared to calculating loan repayments/compound interest.
The former can be trivially done using IEEE floating point. The latter is
an imprecise quantity unless you specify extra rules. Floating point is
probably as good as any format in dealing with it and better than most. No
format can represent general irrational quantities precisely.

>> The idea that it is wrong to test for exact equality is quite incorrect,
>> there are many algorithms where it is perfectly legitimate to test for
>> exact equality if you know you are dealing with IEEE arithmetic.
>
>Agreed.  It's important to remember, though, that the behavior of IEEE
>arithmetic can change depending on the current rounding mode, and the
>programmer may or may not have direct control over that.  However, I
>don't think that affects any cases where it makes sense to test for
>exact equality.

However in situations where all results are exact and within the
precision of the format. So for a useful class of problems rounding
method makes no difference.

-- 
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------





  parent reply	other threads:[~1996-11-24  0:00 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-15  0:00 The disturbing myth of Eiffel portability The Rt Rev'd Colin James III, KOTM 1/96
1996-11-17  0:00 ` The Rt Rev'd Colin James III, KOTM 1/96
1996-11-18  0:00   ` James Youngman
1996-11-20  0:00     ` Piercarlo Grandi
1996-11-21  0:00       ` Paul Johnson
1996-11-27  0:00         ` Piercarlo Grandi
1996-11-28  0:00           ` Don Harrison
1996-11-29  0:00             ` Piercarlo Grandi
1996-11-29  0:00               ` Don Harrison
1996-11-30  0:00                 ` Piercarlo Grandi
1996-12-01  0:00                 ` Jon S Anthony
1996-12-02  0:00                   ` Piercarlo Grandi
1996-11-29  0:00             ` Piercarlo Grandi
1996-11-29  0:00               ` Robert Dewar
1996-11-29  0:00               ` Robert Dewar
1996-11-20  0:00   ` Jeff Miller
1996-11-20  0:00     ` Piercarlo Grandi
1996-11-17  0:00 ` Eoin Woods
1996-11-17  0:00 ` Lawrence Kirby
1996-11-18  0:00 ` Stephen J Bevan
1996-11-19  0:00 ` Kaz Kylheku
1996-11-19  0:00   ` Robert Dewar
1996-11-20  0:00     ` Matt Kennel
1996-11-22  0:00       ` Robert Dewar
1996-11-20  0:00     ` Larry Kilgallen
1996-11-21  0:00       ` Robert Dewar
1996-11-22  0:00         ` Larry Kilgallen
1996-11-22  0:00           ` Robert Dewar
1996-12-01  0:00             ` Graham C. Hughes
1996-12-01  0:00               ` Robert Dewar
1996-12-02  0:00                 ` Brian R. Hanson
1996-12-06  0:00                   ` Robert Dewar
1996-12-09  0:00                     ` Brian R. Hanson
1996-11-26  0:00         ` Van Snyder
1996-11-22  0:00       ` Ken Garlington
1996-11-25  0:00         ` Robert Dewar
1996-11-21  0:00     ` Keith Thompson
1996-11-21  0:00       ` Robert Dewar
1996-11-22  0:00       ` Norman H. Cohen
1996-11-24  0:00       ` Lawrence Kirby [this message]
1996-11-21  0:00     ` Francois Labreque
1996-11-21  0:00       ` Kaz Kylheku
1996-11-24  0:00       ` Robert Dewar
1996-11-20  0:00   ` James Mansion
1996-11-20  0:00     ` Kaz Kylheku
1996-11-25  0:00   ` Joachim Durchholz
1996-11-26  0:00     ` Lawrence Kirby
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox