在评估带有指数后跟乘法的简单表达式时,我在Portland和英特尔fortran编译器之间得到了不同的行为.我很确定pgf90(和gfortran)根据我对运算符优先级的理解而正常工作,但我想要第二个意见,因为这些事情可能会有点棘手.
这是我的代码简化为一个非常基本的形式.当使用ifort运行时,表单的表达式将被ifort d1=a**-2*b
解释为pgf90和gfortran.如果我从指数中删除负号,则所有三个编译器都将其解释为.如果我将*b改为+ b,我也会从这三个中获得良好的行为.d1=a**(-2*b)
d1=(a**-2)*b
d1=(a**2)*b
program badvals
implicit none
real :: a, b, c1, c2, d1, d2
a = 2.
b = 4.
! Works with addition following the exponent.
c1 = a**-2+b
c2 = a**(-2)+b
! Ifort differs with multiplication following negative exponent.
d1 = a**-2*b
d2 = a**(-2)*b
print*, "c1, d1 = ",c1, d1
print*, "c2, d2 = ",c1, d2
print*, "c2-c1, d2-d1 = ",c2-c1, d2-d1
end program badvals
!Program output for ifort v13.0.1.117: (either …
Run Code Online (Sandbox Code Playgroud)