(j3.2006) (SC22WG5.5357) [ukfortran] From a colleague

Bill Long longb
Wed Oct 29 09:14:12 EDT 2014

On Oct 29, 2014, at 4:00 AM, N.M. Maclaren <nmm1 at cam.ac.uk> wrote:

> Obviously, the following code fragments have equivalent problems with NaNs:
>    IF (x) 123,456,789

If X is a NaN this version is not conforming.  I depends on how the implementation was done.  Based on how this was probably originally envisioned, it is more likely that the modern equivalent would be like

if ( x == 0.0) then
    go to 456
else if (sign_bit_of(x) == 1) then
    go to 123
else       !     if (sign_bit_of(x) == 0) then
    go to 789
end if

Note that the test x == 0.0 will always be false for x a NaN, and the test of the sign bit is indifferent to whether x is a NaN or not. 

We could define some semantics of this sort (so close on the keyboard to ?wart?).  But I would not recommend this because I think it misses the larger point.  If the program gets to this state (a NaN in an arithmetic IF statement), it is likely so badly off track that it is better for the standard to just declare that the program is not conforming, and there are no semantics provided to determine what will happen. 

If the programmer had set the halting modes earlier in the program to halt on invalid, the program would likely have stopped before reaching this statement anyway.


>    IF (x < 0.0) GOTO 123
>    IF (x > 0.0) GOTO 789
>    GOTO 456

Bill Long                                                                       longb at cray.com
Fortran Technical Suport  &                                  voice:  651-605-9024
Bioinformatics Software Development                     fax:  651-605-9142
Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101

More information about the J3 mailing list