Formatted Read Accuracy
Toon Moene
toon@moene.indiv.nluug.nl
Wed Oct 9 12:55:00 GMT 2002
Emil Block wrote:
> When reading a number from an input file with a formatted read statement the
> value is not represented correctly when using the G77 compiler. For example,
>
> read (line,3) xllt
> 3 format(f9.4)
>
> input xllt is 67.9936 and it becomes 67.9935989
>
> Anyone know how to correct this?
You can't. 67.9935989 is the approximation that's choosen by the input
algorithm of 67.9936 because the latter can't be represented exactly in
single precision floating point format.
You simply have to live with this, because it's a feature of dealing
with floating point values.
Hope this helps,
--
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