Dear Fortran experts, As a sub problem in my code I need to evaluate the following expression: lim 1 x -> 0+ ------------------ sqrt(-1) + 1/x The expression above is well defined in the extended complex plane. 1/x ---> Inf as x ---> 0. sqrt(-1) + Inf = Inf. 1/Inf = 0. To try it out I wrote a code, compiled and ran it with three different Fortran 95 processors and got two different results. REAL X COMPLEX I PARAMETER(I=(0.0,1.0)) INTRINSIC SIGN X=SIGN(0.0,+1.0) PRINT*,'X=',X PRINT*,'1/X=',1/X PRINT*,'I+1/X=',I+1/X PRINT*,'1/(I+1/X)=',1/(I+1/X) X=SIGN(0.0,-1.0) PRINT*,'X=',X PRINT*,'1/X=',1/X PRINT*,'I+1/X=',I+1/X PRINT*,'1/(I+1/X)=',1/(I+1/X) END In GFortran and Open64 (I+1/X) evaluates to (0.0,1.0) + (+Inf,0.0) = (+Inf,1.0) (assuming X=+0.0) which [probably?] should be interpreted as a the complex infinity. Intel Fortran I got (NaN,0.0) as result. Is this a bug in Intel Fortran or is there something here which I am not thinking of? Am I violating a Fortran rule or IEEE arithmetic rule somewhere? Dr. Fortran (Steve Lionel) kindly pointed it out to me that IEEE 754 does not define complex arithmetic. I assume then that Fortran has at least *some* rules about how complex arithmetic on the *extended* complex plane should be executed by the processor? Keywords: Fortran 95, IEEE 754, complex, extended real, extended complex, arithmetic, reciprocal.
For more complete information about compiler optimizations, see our Optimization Notice.