[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-fortran
Subject:    Re: Floating-point accuracy
From:       Tobias Burnus <burnus () gmx ! de>
Date:       2006-08-09 18:01:50
Message-ID: 44DA230E.3080904 () gmx ! de
[Download RAW message or body]

Hi,

Joel Parker wrote:
> I'm having some trouble with floating-point accuracy in g77 and gfortran,
> and I'm starting to think I'm missing something obvious.

You do. The standard infamous Fortran programmer's problem. (Which took
me also quite long to realize.)

(All results below on AMD64)

If you do:
   N1 = 2453957.09236
you implicitly do
   N1 = real(2453957.09236,4)
This gives for N1:
        2453957.00000000

And for ANS:
   1.06603696098563

if you use
   N1 = 2453957.09236_8 (or 2453957.09236d0 or kind(2453957.09236,4) or ...)
Then the final result is:
   1.06603948966462

Using kind=10 gives:
   1.066039489664613281

And (using the Intel compiler, which implements kind=16 in software as
on ia32 and AMD64 kind=16 does not exist):
   1.06603948966461327857631759069131

> Pentium 4 / Ubuntu 6.06 (fully updated)
>     MATLAB 7.0.1
Matlab probably regards the input automatically as double precision.

> SPARCv9 / Solaris (unknown version)
>     f77: Sun WorkShop 6 update 2 FORTRAN 77 5.3

Seemingly that one wrongly regards the digits as kind=8 or the default
type is already 8 bytes long.

If you use gfortran -Wconversion you see warnings when you convert a
real(4) into a real(8).

Tobias

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic