home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!mips!think.com!Think.COM!sandee
- From: sandee@Think.COM (Daan Sandee)
- Newsgroups: comp.lang.fortran
- Subject: Re: Ignoring Least Significant Bit in a Real Compare
- Date: 21 Aug 1992 21:12:34 GMT
- Organization: TMC
- Lines: 44
- Distribution: world
- Message-ID: <173m82INNkmc@early-bird.think.com>
- References: <1992Aug21.203055.29668@aero.org>
- NNTP-Posting-Host: django.think.com
-
- In article <1992Aug21.203055.29668@aero.org>, wae@aero.org (William A. Emanuelsen) writes:
- |>
- |> TEMP1 = 17266436725301415722
- |> TEMP2 = 17266436725301415723
- |>
- |> They should be equal since TEMP1 is assigned a number,
- |> and TEMP2 = TEMP3 + DELTA, where DELTA = TEMP1 - TEMP3.
- |> (It's really a bit more complicated than this.)
-
- This is (as you know) one of the facts of life when using floating point
- arithmetic. The hardware does not guarantee that X+Y-Y is the same as X.
- So my first reaction is, of course : you're SOL.
-
- |> So what I did was to write a logical function, REQ, to replace the .EQ.
- |> comparison:
- |>
- |> LOGICAL FUNCTION REQ(X1,X2)
- |> REQ = .FALSE.
- |> IF (ABS(X1-X2) .LT. EPS) REQ = .TRUE.
- |> RETURN
- |> END
- |>
- |> So where I formerly had: IF (TEMP1 .EQ. TEMP2) ...
- |> I now have: IF (REQ(TEMP1,TEMP2)) ...
-
- It would be a lot faster if you had a statement function
-
- LOGICAL REQ
- REQ(X1,X2) = ABS(X1-X2) .LT. EPS
-
- Not having an external function call saves two memory writes, an RJ,
- three memory reads, and two EQ (jump) instructions, plus the cost of
- not being able to optimize across a function call.
-
- Depending on how you use it, it might be faster to have a real function,
-
- REQ(X1,X2) = ABS(X1-X2) - EPS
-
- and then test with IF (REQ(X1,X2) .LT. 0.). It would save the compiler
- the trouble of converting the result of the subtract into a logical value.
-
- Daan Sandee sandee@think.com
- Thinking Machines Corporation
- Cambridge, Mass 02142 (617) 234-5044
-