Hello,
the following code shows an issue with nested WHERE constructs, which may lead to an unexpected floating point exception:
program nested_where implicit none integer, parameter :: n = 100 real :: x(n), y(n) real :: z = log (0.5) call random_number (x) y = 1 ! "Good initialization" y = 0 ! "Bad initialization" print *, count (x == 1) ! Prints 0 where (x > 0.5) y = x where (log (y) > z) ! The "dangerous mask" x = 1 end where end where print *, count (x == 1) ! Not reached for y=0 end program nested_where
% ifort -g -traceback nested-where.f90 -fpe0 && ./a.out
0
forrtl: error (73): floating divide by zero
Image PC Routine Line Source
a.out 080A551C Unknown Unknown Unknown
a.out 0804A396 MAIN__ 11 nested-where.f90
a.out 0804A0B6 Unknown Unknown Unknown
I had a discussion at
https://groups.google.com/forum/#!topic/comp.lang.fortran/EG2k49ujggA
which appears to support the idea that a standard-conforming compiler should mask the bad values before evaluation of the inner mask.
Or am I missing something?