Formatted Read Accuracy
Toon Moene
toon@moene.indiv.nluug.nl
Thu Oct 10 14:28:00 GMT 2002
Emil Block wrote:
> I have confirmed with a debuger (and write statements) that "line" indeed
> contains 67.9936, and after the read the value is 67.9935989 with G77 and is
> 67.9936 with F77.
I'm afraid I just don't see your problem.
I tried the following complete, stand-alone program:
$ cat trivial.f
READ '(F9.4)',X
PRINT '(F9.4)',X
END
$ g77 trivial.f
$ ./a.out
67.9936
67.9936
The second `67.9936' is the output of the program - seems perfectly OK
to me ...
Now, if you really want to be scared s***less, try the following with
your favourite Fortran compiler:
$ cat trivial2.f
READ '(F12.0)',X
PRINT '(F12.0)',X
END
$ <fortran-compiler> trivial2.f
$ ./a.out
839380840.
???? <- Scary, ain't it :-)
Floating point arithmetic - not for the faint-of-heart.
--
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
More information about the Gcc-help
mailing list