Printing constant 0.8804418
in Fortran
program hello
print *, 0.8804418
end program hello
gives 0.880441785
while the C version
#include <stdio.h>
int main() {
printf("%.10g", 0.8804418);
}
prints 0.8804418
on the same system (Linux x86-64 with gfortran and gcc). Why is the output different? Note that increasing precision in printf
doesn't change output.
This is not a duplicate of Is floating point math broken? or similar. This question is specifically about difference in Fortran and C representation (or formatting).