non-compatible round-off when printing for gfortran

Dominique Dhumieres dominiq@lps.ens.fr
Fri Jul 20 17:43:00 GMT 2007


> However, the original thread was not about rounding "0.2500000"

In fact there is, gfortran on one hand and xlf and g95 in the other
do not use the same rounding for such cases:

print '(F10.0,F10.1,F10.2,F10.3)', 0.5, 0.25, 0.125, 0.0625
print '(4(F10.1))', 0.15, 0.35, 0.55, 0.85
end

gives

        1.       0.3      0.13     0.063
       0.2       0.3       0.6       0.9

with gfortran and

        1.       0.2      0.12     0.062
       0.2       0.3       0.6       0.9

with xlf and g95. The first line is made of (negative) powers
of 2 and are represented exactly for any FP mode, gfortran round
to up, while xlf and g95 round to even. The second line is made
of numbers without exact representation and the results depend
on the sign of the approximation, but not on the compiler (at least
in this case).

Indeed this does not preclude more general rounding problems
with 80 bit representations and so on.

Dominique



More information about the Fortran mailing list