Re: IF THEN function in Digital Fortran 5.0A

From: Ken Plotkin (kplotkin_at_nospam-cox.net)
Date: 04/10/04


Date: Sat, 10 Apr 2004 10:53:32 -0400

On Sat, 10 Apr 2004 04:23:40 -0400, "noi" <noi508@hotmail.com> wrote:

> Do you mean that there is no way to work around this problem?

It's not a problem. It's a fact of life. I's also a very commonly
asked question.

>Will it help if I use increase the PRECISION (i.e using REAL (8) instead of
>REAL)

No.

>As I mentioned, I did use the ABS function to solve this small difference
>However, this task becomes tedious since it is against the common logic
>(when A = B, it is much easier to write IF (A .EQ.B) THEN than IF
>(ABS(A-B).LE.0.00001) THEN)

You've done the right thing. When people ask this question, that's
what the answer generally is.

There are instances where a test of equality between two floating
point numbers is meaningful, but usually it's not.

A few details:

o Instead of hard-wiring 0.00001, I recommend using a variable or
parameter. Then you can tune it to the physical reality of your
calculation.

o The "equality" criterion depends on the magnitude of A and B. If A
and B are in the trillions, their difference (even if just the last
bit) is going to be a lot bigger than 0.00001.

o Take a look at the intrinsic function EPSILON. That gives you a
value commensurate with the precision of the machine.

Welcome to the world of digital precision. :-\

Ken Plotkin



Relevant Pages

  • Re: Where do chimps come from?
    ... inability to understand what evidence is and what it means for evidence ... hint on above that unequivocally falsifies a hypothesis of common ... the less extraordinary claim even with no more evidence than "life ... Finding fossils is great because it gives historical details of how the ...
    (talk.origins)
  • Re: Where do chimps come from?
    ... inability to understand what evidence is and what it means for evidence ... hint on above that unequivocally falsifies a hypothesis of common ... hypothesis of common design can be made to fit any data. ... the less extraordinary claim even with no more evidence than "life ...
    (talk.origins)
  • Re: Bruijn babbles bullshit
    ... error allowed in equality". ... Is there a BEST 'like' and can it be identified with common equality? ... to agree with Brouwer's Continuity Theorem. ... only the "best like = equals" has been programmed in the end. ...
    (sci.math)
  • The Cosmic Systems Input and Output
    ... Here is an alternative to Darwin's theory of common descent from a simple ... the phenotype universe, or the cosmic system's input and output -- is the ... pending the discovery of an even higher form of non-human life. ... for the Advancement of Science realized, "Scientists can't sell it alone." ...
    (sci.bio.systematics)
  • Re: Bruijn babbles bullshit
    ... error allowed in equality". ... Is there a BEST 'like' and can it be identified with common equality? ... to agree with Brouwer's Continuity Theorem. ... only the "best like = equals" has been programmed in the end. ...
    (sci.math)