$ cat nan-find.f90 program main real :: a,b,c logical :: l b = 0. c = 0. a = b/c call nanfind(a,a,l) if (l) then print *,a,"compares equal to itself" else print *,a,"compares unequal to itself" end if end program main
subroutine nanfind(a,b,l) real,intent(in) :: a,b logical, intent(out) :: l l = a == b end subroutine nanfind $ gfortran -O3 -ffast-math -fno-finite-math-only nan-find.f90 $ ./a.out NaN compares equal to itself $ gfortran -v Using built-in specs. Configured with: ../gcc/configure --prefix=/home/ig25 --enable-languages=c,c++,f95 : (reconfigured) ../gcc/configure --prefix=/home/ig25 --enable-languages=c,c++,f95 Thread model: posix gcc version 4.0.0 20041221 (experimental) $ Then again, I never liked the fact that NaNs can compare equal with any compiler option... -- Summary: -fno-finite-math-only does not override -ffast-math Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: driver AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: Thomas dot Koenig at online dot de CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19116