IF (X .NE. X) THEN ! this will be true if X is NaN program test_nan implicit none real*4 x x = -100.0 x = sqrt(x) if (x.eq.x) then print*,'it is not a NaN' endif if(x.ne.x) then print*,'it is a Nan' endif end program test_nan