I am working with some small double precision values (<0.001) in C++. I need to do the same calculation in Fortran. This same calculation is showing different result in Fortran. Most result values differ after the 5th or 6th decimal place, but some values match exactly.
How do I get the correct result in Fortran? Why is this happening?
C++ Code:
double A[3][10], B[10][5];
//values of A and B are initialized with values <.001
double tmp;
tmp=0.008456278; //for example
int p;
for (p=1;p<10;p++)
{
tmp=tmp-A[2][p]*B[p][4];
}
cout<<"Result="<< tmp;
Fortran Code:
real*8 :: A(3,10)
real*8 :: B(10,5)
!values of A and B are initialized with values <.001
real*8 :: tmp
tmp=0.008456278 !value for example
integer :: p
do p=1, 10
tmp=tmp-A(2,p)*B(p,4)
end do
write(*,*) "Result=", tmp