I have a simple question to ask. I have written two similar programs in FORTRAN90 and C. Both sources are built within CYGWIN environment. They are very simple:
1 2 3 4 5 6 7 8 9 10 11
PROGRAM test
DOUBLE PRECISION Na, Nb, Nr
Na = 0.2726
Nb = -0.2727
Nr = Na + Nb
WRITE(6,*)'Nr = ',Nr
END
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <stdio.h>
int main(void) {
double Na, Nb, Nr;
Na = 0.2726;
Nb = -0.2727;
Nr = Na + Nb;
printf("Nr = %.16E\n", Nr);
return 0;
}
CYGWIN reported following results:
1 2 3 4 5 6 7
Konstantin@Konstantin-HP /home/lbm2d
$ ./testf.x
Nr = -1.0001659393310547E-004
Konstantin@Konstantin-HP /home/lbm2d
$ ./testc.x
Nr = -9.9999999999988987E-05
As you can see, the problem is adding two decimals. However, both results are incorrect and different. Can somebody explain why?