The following program:
FUNCTION F(r,a,e)
REAL*8 :: a(2:15)
REAL*8 :: r,f,e
f=0
DO i = 2, 15
f = f + a(i)/(r**(i-1)*REAL(i-1,8))
END DO
f=f-e
END FUNCTION F
PROGRAM TEST
REAL*8 :: a(2:15)=(/-195.771601327700D0, 15343.7861339500D0, &
-530864.458651600D0, 10707934.3905800D0, &
-140099704.789000D0, 1250943273.78500D0, &
-7795458330.67600D0, 33955897217.3100D0, &
-101135640744.000D0, 193107995718.700D0, &
-193440560940.000D0, -4224406093.91800D0, &
217192386506.500D0, -157581228915.500D0/)
REAL*8 :: r=4.51556282882533D0
REAL*8 :: e=-2.21199635966809471000D0
REAL*8 :: f
write(6,*) f(r,a,e)
END PROGRAM TEST
generates different results with gfortran 4.3.0 at O0 and O3
> gfortran -O0 -march=k8 -msse test.f90
> ./a.out
0.00000000000000
> gfortran -O3 -march=k8 -msse test.f90
> ./a.out
-1.143973804573761E-012
notice that this is without -ffast-math and with sse.
gfortran 4.1 gives 0.0 in all cases.
I suspect that the reason is that
__powidf2
is replaced by inline code at -O3 that gives slightly different results.
If this is expected behavior, maybe this substitution should be guarded by
-ffast-math ?
--
Summary: different results between O3 and O0
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jv244 at cam dot ac dot uk
GCC build triplet: x86_64-unknown-linux-gnu
GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33780