This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Optimisation prevents overflow?
- From: Davide Mancusi <arekfu at yahoo dot it>
- To: fortran at gcc dot gnu dot org
- Date: Thu, 19 Jul 2007 23:05:06 +0200
- Subject: Optimisation prevents overflow?
Hi,
Can anyone enlighten me on this one? Have a look at the following:
program fk
double precision a, olda
integer i
a=1.d0
i=0
do
i=i+1
olda=a
a=a*1.5d18
print *, a
if(a.le.olda) exit
end do
print *, "when printing, overflow at step ", i
a=1.d0
i=0
do
i=i+1
olda=a
a=a*1.5d18
if(a.le.olda) exit
end do
print *, "when not printing, overflow at step ", i
end program fk
If compiled with
$ gfortran fk.f -o fk
I get
1.500000000000000E+018
2.250000000000000E+036
3.375000000000000E+054
5.062499999999999E+072
7.593749999999999E+090
1.139062500000000E+109
1.708593750000000E+127
2.562890624999999E+145
3.844335937499999E+163
5.766503906249998E+181
8.649755859374997E+199
1.297463378906250E+218
1.946195068359374E+236
2.919292602539062E+254
4.378938903808593E+272
6.568408355712889E+290
+Infinity
+Infinity
when printing, overflow at step 18
when not printing, overflow at step 18
But if I use optimisation
$ gfortran fk.f -o fk
I get
1.500000000000000E+018
2.250000000000000E+036
3.375000000000000E+054
5.062499999999999E+072
7.593749999999999E+090
1.139062500000000E+109
1.708593750000000E+127
2.562890624999999E+145
3.844335937499999E+163
5.766503906249998E+181
8.649755859374997E+199
1.297463378906250E+218
1.946195068359374E+236
2.919292602539062E+254
4.378938903808593E+272
6.568408355712889E+290
+Infinity
+Infinity
when printing, overflow at step 18
when not printing, overflow at step 273
Is optimisation preventing overflow? What is really happening here?
Thanks for the help :-)
Davide
--
A tautology is a thing which is tautological.
--
Time flies like an arrow. Fruit flies like a banana.