program TestNegativeZero ! Check for negative zero ! by James Van Buskirk as posted at comp.lang.fortran on 21 August 2007. ! By default, IVF does not take care to distinguish ! minus zero. You may get it in some calculations, but tests for it ! won't show a difference and it won't show in formatted output. ! There's a switch -assume minus0 which enables that. by ! Steve Lionel as posted at comp.lang.fortran on 21 August 2007. logical :: is_negative_zero real :: y complex :: x x=cmplx(1.0,-0.0) y=aimag(x) ! Assignment and Test works with G95(no options) and with Intel ! ifort(with above assume option). is_negative_zero = aimag(x) == 0 .AND. sign(real(1,kind(x)),aimag(x)) < 0 write (*,*) "Complex case: is_negative_zero=",is_negative_zero is_negative_zero = y == 0 .AND. sign(real(1,kind(y)),y) < 0 write (*,*) "Real case: is_negative_zero=",is_negative_zero end