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: floating point discrepancy


On 4/6/2011 1:42 PM, Sebastian Berchtold wrote:
Hi,
i'm not a fortran programmer. I just try to port some code to the jvm.

But i ran into significant discrepancies when dividing two numbers.
I just give you the example im struggling with:
28.503076184326837 / 2.41191E-003

11817.636721240358
11817.636384715817
          .

the first result is consistently from java/c/wolframalpha
while the second result is from my gfortran compiler.
I'm using the current package on ubuntu, gcc version 4.4.5.


This makes me serious trouble. So my question is how can i reach more consistent results? But also where can such a discrepancy come from? It's not like we're on the last digit here =)

Thank you in advance,
S.B.


Sebastian,


you are doing single precision floating point arithmetic:
28.503076184326837 / 2.41191E-003=  11817.636718750000

You need to be explicit when you want double precision:
28.503076184326837D0 / 2.41191D-003=  11817.636721240358

Kindly,
H.



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