Hey guys,
In general, given a Fortran application, should differences between the 32 bit and 64 bit results be expected?
If all calculations are single precision, it seems that differences can arise in even a simple program. For instance, the following program might represent a fairly complex scientific calculation, showing that significant differences might occur when using single precision arithmetic.
Is that right? Why should there be any difference at all?
Thanks!
!-------------------------------------------------
! with real*4 x,y,z,sum
! using (2.0*i*pi/num)
! 32 bit sum = -0.0030936133116484
! 64 bit sum = -0.0020905509591103
!
! using (2.d0*i*pi/num)
! 32 bit sum = -0.0028321230784059
! 64 bit sum = -0.0028321230784059
!
! with real*8 x,y,z,sum
! using (2.0*i*pi/num)
! 32 bit sum = 0.0000000000347261
! 64 bit sum = 0.0000000000254766
!
! using (2.d0*i*pi/num)
! 32 bit sum = 0.0000000000010576
! 64 bit sum = 0.0000000000010576
!-------------------------------------------------
program simpleSum
real, parameter :: pi=3.14159265358979
real*8 :: x,y,z,sum
integer :: i,j,k,num
!
sum = 0.0
num = 1000
do i=1,num
x = cos(2.0*i*pi/num)
do j=1,num
y = sin(2.0*j*pi/num)
do k=1,num
z = cos(2.0*k*pi/num)
sum = sum + x*y*z
enddo
enddo
enddo
!
write(*,'(f25.16)') sum
!
pause
!
end program simpleSum