[comp.lang.fortran] Check for NAN in fortran

jim@interet.UUCP (User) (01/09/91)

We check for NAN as follows:
      if(dnum*0d0 .ne. 0d0) write(*,1)
1     format(' The variable dnum is equal to NAN!')

The point is that NAN times zero is NAN for machines that use NAN.
Unfortunately the above code can be defeated by compiler optimizations,
so you may need to write:
      if(impossible) then
        dzero=1.d0
      else
        dzero=0d0
      endif
      if(dnum*dzero .ne. 0d0) write(*,1)
1     format(' The variable dnum is equal to NAN!')

where "impossible" is some impossible logical expression.
I hope this helps.

Jim Ahlstrom        uunet!interet!jim