HP3000-L Archives

January 1999, Week 1

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Bruce Toback <[log in to unmask]>
Reply To:
Bruce Toback <[log in to unmask]>
Date:
Tue, 5 Jan 1999 15:43:29 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (61 lines)
Michael Anderson writes:

>I have been writing COBOL code for the last 9-10 years, and the last six
>months Fortran 66. Now converting the 66 code to 77.  It seems
>ridiculous that I am not able to use a simple "IF" statement to see if a
>double precision variable is equal to zero in FORTRAN 77.
>IF (ZAMOUNT .EQ. 0.00D0) ...
>
>A compile warning (781) states: Test may fail due to floating point
>imprecision.

This is a brain-damaged warning, probably put in because of some customer
complaint about something the customer should have been aware of to begin
with. ((Kind of like "Caution: This beverage is hot" on a coffee cup.)

If what you want is a comparison for exactly zero, ignore the warning. If
what you want is a comparison to "close enough to zero", use the other
form. The "close enough to zero" case occurs when you've been adding and
subtracting floating-point values from different sources. For example,
the comparison:

     if (1.0 / 3.0 - 0.333 .EQ. 0.0)

will fail because the result of the division is NOT exactly 0.333. On the
other hand, if you're doing something like:

     z = 0.0
       .
       .
       .
     if (a .eq. b) <do something that changes z>
       .
       .
       .
     if (z .EQ. 0)

The exact comparison will do what you expect. In short, if you're working
with numbers that you know to be inexact, use inexact comparisons, like
your sample

>IF (ZAMOUNT .LT. 0.0001 .AND. ZAMOUNT .GT. -0.0001) .....

Otherwise, ignore the warnings. Also, if the code worked in Fortran 66,
it will certainly work in compatibility-mode Fortran 77, and will almost
certainly work in native mode Fortran 77. If it works in 66 but not in
native mode 77, then you should fix your code, since there were probably
cases in Fortran 66 where it broke but the failure went undetected.

-- Bruce


--------------------------------------------------------------------------
Bruce Toback    Tel: (602) 996-8601| My candle burns at both ends;
OPT, Inc.            (800) 858-4507| It will not last the night;
11801 N. Tatum Blvd. Ste. 142      | But ah, my foes, and oh, my friends -
Phoenix AZ 85028                   | It gives a lovely light.
btoback AT optc.com                |     -- Edna St. Vincent Millay
Mail sent to [log in to unmask] will be inspected for a
fee of US$250. Mailing to said address constitutes agreement to
pay, including collection costs.

ATOM RSS1 RSS2