Re: Does "gfortran -O0" truncate floating point numbers to their expected precision?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/3/2013 7:22 AM, Guan Xin wrote:
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
This doesn't look to me like F77, although it contains some F66.
If you are using 32-bit gfortran, the i486 code with x87 instructions is particularly prone to this kind of problem. Did you try -march=native, or, if using an extremely old CPU, -ffloat-store?

--
Tim Prince





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux