Take the 2-minute tour ×

I have a FORTRAN code that I need to run on a server. I noticed that the results are a little different between the two machines. Looking into it, I learned that the difference rise from a function which return a real value to a double precision variable. On the locale machine I use old compiler (gnu f95 4.1.2) and on the remote machine I use ifort.

share|improve this question

2 Answers 2

up vote 5 down vote accepted

You should expect small difference between the same program compiled by different compilers. Finite precision arithmetic doesn't obey the rules that we expect for real numbers. So if the compilers change the order of operations, the results may differ slightly.

That said, gfortran 4.1 is very old to point of being obsolete. I wouldn't use a version of gfortran earlier than 4.3. I strongly recommend upgrading.

share|improve this answer
Thanks. The short answer is that I can't upgrade it. The numbers I get (for example) are -8.442167043685913E-003 against -8.442166328430176E-003. Is this difference as small as you describe? –  Yotam May 21 '13 at 11:04
That difference is reasonable if the calculation is done in single precision before being assigned to a double precision variable. It only differs on the 6th decimal place, which is all that you can expect in single precision. If done in double precision, it is larger than typical, but still possible, depending... –  M. S. B. May 21 '13 at 11:16

Note that it is probable that your real value is a 32-bit floating-point number while the double precision is 64-bit. I suspect that the difference in results is due to the different ways in which the two compilers fill up the extra bits in the double precision variable when passed a real value. However, the default size of a Fortran real is compiler-dependent and can be set by compiler options, so check your documentation and compilation options.

double precision is now deprecated but is required to provide more precision than a default real though successive Fortran standards are silent on how much more precision is to be provided. It is reasonable to expect most compilers on most computers to default to 64-bits for double precision, but you might not want to bet your mortgage on a reasonable expectation.

share|improve this answer
Double precision is now deprecated? What should I be using instead? –  Matt May 22 '13 at 3:34
I tend to use the kind. parameters (e.g. real64, int32) defined in the intrinsic module iso_fortran_env these days. If your compiler doesn't provide this yet, look at the function selected_real_kind and how it is used. –  High Performance Mark May 22 '13 at 5:30

Your Answer


