This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: g77 bug?


ccpan wrote:

> The following program compiled with g77 version 2.96 20000731 (Red Hat Linux
> 7.0) will print 3.14159274 as the answer, which is obviously wrong.  Any
> suggestions?

> program test
> double precision pi
> pi = 3.141592654
> print *, pi
> stop
> end program

Unfortunately (for you) this is the correct answer according to the
Fortran standard (77, 90 and 95).  3.141592654 without any qualifier is
a single precision number, hence its accuracy cannot be better than
about 7 digits (using 32-bit floating point numbers).  This matches well
with the answer you get (3.14159274).  If you want a double precision
constant, write 3.141592654d0.

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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]