Code:
! test_eqv.f90
program test_eqv
implicit none
real :: x, y
character(len=100) :: str
x = huge(x)
x = x**2 / x**3 ! Evaluates to NaN. Intended.
write (str, *) x
read (str, *) y
write (*, *) x, y, str
write (*, *) x <= 0.0, y <= 0.0, (x <= 0.0 .eqv. y <= 0.0), (x <= 0.0 .neqv. y <= 0.0)
if (x <= 0.0 .eqv. y <= 0.0) then
write (*, *) 'Right.'
else
write (*, *) 'Wrong!'
stop 1
end if
end program test_eqv
Test:
$ uname -a && gfortran --version && gfortran test_eqv.f90 -Ofast && ./a.out
Linux zX11 6.2.0-32-generic #32~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 18 10:40:13 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
GNU Fortran (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
NaN NaN NaN
F F F F
Wrong!
Note: The following floating-point exceptions are signalling: IEEE_INVALID_FLAG
STOP 1
Is this expected? I understand that -Ofast
affects the evaluation of floating-point expressions, but does it affect things like eqv
as well?
Thanks.