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?

+2


source to share


3 answers


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.

+2


source


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.

+2


source


I am assuming you are using Intel. Try to compile without optimization.

0


source







All Articles