non-compatible round-off when printing for gfortran

Tobias Burnus burnus@net-b.de
Fri Jul 20 09:27:00 GMT 2007


Hi,

satyaakam goswami wrote:
> For gfortran it outputs:
> 0.2 0.2 0.2 0.2 0.3 0.3 0.3 0.3 0.3 0.3
> 0.3 0.3 0.3 0.3 0.4 0.4 0.4 0.4 0.4 0.4
and openf95 outputs the same.

> but for other compiler i tried (g77 and f77 from forte) it outputs:
> 0.2 0.2 0.2 0.2 0.2 0.3 0.3 0.3 0.3 0.3
> 0.3 0.3 0.3 0.3 0.4 0.4 0.4 0.4 0.4 0.4
and g95, ifort and sunf95 have this output
whereas NAG f95 prints the same except with an extra " " at the end.
(I ignore the extra space for now.)

The difference is how the fifth value in the first row is printed:
openf95, gfortran: 0.3
others: 0.2

Ad hoc I don't see why the others print "0.2" for "0.2500000"; following
normal school maths one would round to 0.3.

The Fortran 2003 standard says this is implementation defined.

Note that Fortran 2003 allows one to specify what is done:
- RU (round up), RD (round down) (and some more) edit specifiers
- The ROUND= specifier to data transfer statements (e.g. WRITE)
- The ROUND= specifier of the OPEN statement

However, none of them are currently implemented in gfortran.

Tobias



More information about the Fortran mailing list