Re: IF THEN function in Digital Fortran 5.0A
From: Ken Plotkin (kplotkin_at_nospam-cox.net)
Date: 04/10/04
- Next message: Ken Plotkin: "Re: End of file problems"
- Previous message: Gerry Thomas: "Re: "Visual" Fortran?"
- In reply to: noi: "Re: IF THEN function in Digital Fortran 5.0A"
- Next in thread: Richard Maine: "Re: IF THEN function in Digital Fortran 5.0A"
- Reply: Richard Maine: "Re: IF THEN function in Digital Fortran 5.0A"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Ken Plotkin: "Re: End of file problems"
- Previous message: Gerry Thomas: "Re: "Visual" Fortran?"
- In reply to: noi: "Re: IF THEN function in Digital Fortran 5.0A"
- Next in thread: Richard Maine: "Re: IF THEN function in Digital Fortran 5.0A"
- Reply: Richard Maine: "Re: IF THEN function in Digital Fortran 5.0A"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|