This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: non-compatible round-off when printing for gfortran


On Fri, Jul 20, 2007 at 07:43:15PM +0200, Dominique Dhumieres wrote:
> > 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.
> 

troutmask:sgk[205] gfc -o z -O a.f90        <-- gfortran 4.2.1-some_date
troutmask:sgk[206] ./z
        1.       0.3      0.13     0.063
       0.2       0.3       0.6       0.9
troutmask:sgk[207] gfc4x -o z -O a.f90      <-- gfotran trunk from yesterday.
troutmask:sgk[208] ./z
        1.       0.3      0.13     0.063
       0.2       0.3       0.6       0.9

Perhaps, everyone should use gfortran on FreeBSD-*-amd64 :-)

-- 
Steve


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]