Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26755 Discussions

Ifort Bug with unary minus after operator

Sagan__David
Beginner
112 Views
Consider the following program: program bug real a,b,c a = 1.0 c = 2.0 write(*,*) "FOO: ", a/-1.0/c write(*,*) "FOO: ", a/1.0/c b = a/-1.0/c write(*,*) "FOO: ", b end program Running with ifort 17.0.7 gives: > ifort bug.f90 -O0 > ./a.out FOO: -2.000000 FOO: 0.5000000 FOO: -0.5000000 Notice that the first and third print statements should give the same results. Also note that, in any case, using a unary minus after an operator without parentheses is not a good idea and should be avoided.
0 Kudos
2 Replies
Juergen_R_R
Valued Contributor I
112 Views

The code violates the Fortran standard. Two consecutive unary operators, - and / are not allowed. This is considered as extension, and the processor (compiler) can do whatever it wants. Possibly ifort decides to first execute the second fraction, giving -0.5, and then 1.0/(-0.5) gives -2.000. ifort -e08 rejects the code, nagfor rejects it always, and also gfortran with -std=f2008 rejects it. Without this, it accepts it as extension giving the desired result, but you should never count on that.

Reply