I am getting different behavior between Portland and Intel fortran compilers when evaluating a simple expression with an exponent followed by a multiply. I am pretty sure that pgf90 (and gfortran) are working correctly based on my understanding of operator precedence, but I would like a second opinion since these things can get a bit tricky.
Here is my code simplified down to a very basic form. When run with ifort the expression of the form d1=a**-2*b
gets interpretted as d1=a**(-2*b)
by ifort by as d1=(a**-2)*b
by pgf90 and gfortran. If I remove the negative sign from the exponent, all three compilers interpret this as d1=(a**2)*b
. If I change *b to +b I also get good behavior from all three.
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 -O0 or -fast):
! c1, d1 = 4.250000 3.9062500E-03
! c2, d2 = 4.250000 1.000000
! c2-c1, d2-d1 = 0.0000000E+00 0.9960938
!Program output for pgf90 v12.10-0: (either -O0 or -fast):
! c1, d1 = 4.250000 1.000000
! c2, d2 = 4.250000 1.000000
! c2-c1, d2-d1 = 0.000000 0.000000
!Program output for gfortran v4.1.2: (either -O0 or -O3):
! c1, d1 = 4.250000 1.000000
! c2, d2 = 4.250000 1.000000
! c2-c1, d2-d1 = 0.000000 0.000000
Is there a history behind these differences so that they should be considered a "feature"? Or, is this an outright bug on Intel's part?