Does "gfortran -O0" truncate floating point numbers to their expected precision?
Guan Xin
guanx.bac@gmail.com
Wed Jul 3 11:23:00 GMT 2013
Hello,
I have some Fortran 77 code like this (it's not me who wrote it) --
c f1 and f2 are of the same floating point type
c func() returns the same value on every call
10 f1 = func()
20 f2 = func()
c f1 and f2 are expected to have the same value
30 if (f1 - f2) 100,200,300
When compiled without optimization, the "if" branches to line 200
as expected.
When compiled with optimization, at line 30 the value of f2 still
remains in the register, which has extended precision, and f1 has
already been truncated. Therefore, line 30 will branch to anywhere
depending on the rounding of f1.
My question is: Does "gfortran -O0" guarantee that both f1 and f2
are truncated by line 30, so they compare equal?
Thanks in advance!
Guan
More information about the Gcc-help
mailing list