arrays - Why are these two calculations which are exactly same giving different results in Fortran using gfortran? -
real, dimension(3), parameter :: boxlen = [4.0, 5.0, 7.0] real, parameter :: mindist = 0.1 integer ::i write(*,"(a)") "operation on array" print*, floor(boxlen/mindist) write(*,"(/a)") "operation on individual elements" i=1,3 print*, i, floor(boxlen(i)/mindist) enddo this when run code.
operation on array 40 50 70 operation on individual elements 1 39 2 49 3 69 can explain why 2 calculations (one using operation on array , using operation on individual elements) giving different results? think should same.
for me gfortran 4.8.2 on x86_64-linux-gnu get
operation on array 40 50 70 operation on individual elements 1 40 2 50 3 70
peering crystall ball, if you're using 32-bit x86, there difference in order of how computed values stored memory , printed.
also, looking @ generated intermediate code "-fdump-tree-original", seems array operation, division done @ compile time, (so should @ least correctly rounded mpfr).
Comments
Post a Comment