PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Course

extra odd significant digits

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
merrittr



Joined: 20 Aug 2008
Posts: 1

PostPosted: Wed Aug 20, 2008 11:25 pm    Post subject: extra odd significant digits Reply with quote

Hi

I am doing to I.T. support form some engineers that have some code written the problem is:

some variables are declared as double precision
for example
c_s = .4
the above show up in the watch windo as .40000000560488
all the variables wether declared as constants or calculated do this
I thought this strange but then realized

the PCs are 64bit intel and the OS is 32 bit WinXP and the fortran compiler is also 32 bit PGI fortran , will this account for the above goofyness?
Back to top
View user's profile
Christopher Hulbert



Joined: 01 Dec 2005
Posts: 76

PostPosted: Thu Aug 21, 2008 4:02 am    Post subject: Reply with quote

0.4 is not exactly representable in floating point (perhaps a document like this one will provide more floating point reference http://docs.sun.com/source/806-3568/ncg_goldberg.html).

One thing to note is that it looks like the 0.4 is being represented as single and then stored in a double precision variable. You should get more accurate results using 0.4d0 as shown below.

[chulbert@fourier ~]$ cat fp.f90
program fp
double precision :: a,b

a = 0.4
b = 0.4d0

WRITE(*,'(f20.18 f20.18)') a,b
end program
[chulbert@fourier ~]$ pgf90 -V

pgf90 7.2-4 64-bit target on x86-64 Linux -tp k8-64e
Copyright 1989-2000, The Portland Group, Inc. All Rights Reserved.
Copyright 2000-2008, STMicroelectronics, Inc. All Rights Reserved.
[chulbert@fourier ~]$ pgf90 fp.f90
[chulbert@fourier ~]$ ./a.out
0.4000000059604645000.400000000000000000
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group