non-compatible round-off when printing for gfortran
Tim Prince
tprince@myrealbox.com
Fri Jul 20 14:03:00 GMT 2007
satyaakam goswami wrote:
> Hi
> There is an incompatibility in round-off when printing between
> gfortran (i tried both gcc411 and 412) and other fortran compiler (i
> tried g77 from gcc3.2.3 and f77 from SUN forte 7 and 8)
> Here is an example, it says better than me.
> program test
> real myr(10)
> integer i
> do i=1,10
> myr(i)=0.2+0.01*i
> enddo
> write(*,1) (myr(i),i=1,10)
> do i=1,10
> myr(i)=0.3+0.01*i
> enddo
> write(*,1) (myr(i),i=1,10)
> 1 format (10(f3.1,1x))
> end
>
> 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
> 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
>
> I understand that correct round-off is "phylosofic issue" here, but
> that causes inconvinience for cross-platforming and porting.
>
These results surely will change when you go between extended precision
and non-extended. gfortran does have control over that. Default for
i386 is -mfpmath=387 (extra precision) while for x86-64 it is
-mfpmath=sse (no extra precision). If stuff like this is critical for
your applications, you will also need attention to the data types of
your constants. If high precision is important, you would evidently
want 0.2d0, 0.01d0,... or the f90 equivalents.
More information about the Fortran
mailing list