Fortran compiler 4 vs 11
I am migrating an application from an older version of fortran (4.0) to a newer version (11.0). While porting, I ran into some problems with real * 4 variables:
real*4 a,b,c a=0.9876875 b=0.6754345 c=a*b
for c
in the old compiler 0.667118
, which is the correct value. But with the new compiler I get a little change from the output (c variable) eg 0.667120
. Although this is a slight variation, I use these values โโin some other calculations. So the overall result makes a huge difference. How to overcome this problem?
You are, I assume, going from Microsoft Fortran Powerstation 4 to Intel Visual Fortran 11.xx?
Anyway, try this:
program test32 integer, parameter :: iwp = selected_real_kind(15,300) real(iwp) :: a,b,c a=0.9876875 b=0.6754345 c=a*b write(*,'(3f12.8)')a,b,c end program test32
which produces:
0.98768753 0.67543453 0.66711826
I will not explain select_real_kind, not because I donโt want to, but because help will probably do it much better. But ask if something is not clear here.
ps The representation of real * 4 or any type of real is processor dependent and compiler dependent and this is one of the reasons you get different results.
source to share
A discussion of the changes in Intel Visual Fortran compiler version 11 is here:
http://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/68587/
The result is that older versions of the Fortran compiler unambiguously promote values โโfrom one precision to double precision before performing the operation. The default behavior in version 11 is to perform an operation using one precision. There are compiler options ( /arch:ia32
) to enable the old behavior in the new compiler.
source to share