PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

real*8 conversion errors

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



Joined: 27 Oct 2004
Posts: 3

PostPosted: Wed Oct 27, 2004 10:07 am    Post subject: real*8 conversion errors Reply with quote

I have the following test program on:
Linux Red Hat 8.0 kernel 2.4.18-14
GLIBC version 2.2.93-5
PGF77 version 5.1-2

program newtest

implicit none

real*8 myreal, newreal

myreal = 25.13982364598249
newreal = 17.77777777777777

write(*,*) 'myreal = ',myreal
write(*,*) 'newreal = ',newreal

end

The output of this program is:
myreal = 25.13982391357422
newreal = 17.77777862548828
The output values are obviously not the same as in the code.

Has anyone else come across this problem and if so what was done to correct it? I would imagine it to be a compiler bug. Any input would be very helpful.
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6123
Location: The Portland Group Inc.

PostPosted: Wed Oct 27, 2004 12:49 pm    Post subject: Reply with quote

Hi Bland,


Actually, its not a compiler bug. In fortran, real literal constants have an implict kind just like variables. So what's happening is at compile time your constant values are being truncated to fit the default size of a "real" which is 4 bytes.

With pgf77 and pgf90 you can add the compilation flag "-r8" to change the implicit kind for reals to be "real*8". Also with pgf90, you can append the real literal constant with a kind parameter.

Example:
myreal=25.13982364598249_8

Hope this clarifies things,
Mat


Last edited by mkcolg on Mon Feb 07, 2005 3:02 pm; edited 1 time in total
Back to top
View user's profile
cyrus



Joined: 13 Jan 2005
Posts: 2

PostPosted: Thu Jan 13, 2005 1:02 am    Post subject: Reply with quote

Hello,

Does this mean that only specify REAL*8 in the code is not enough?

Thanks
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6123
Location: The Portland Group Inc.

PostPosted: Thu Jan 13, 2005 9:23 am    Post subject: Reply with quote

REAL*8 only applies to the variable not the literal constant. Constants also have a "kind". If you want this kind to be anything other than the default, you must specify it. See Michael Metcalf and John Reid's Fortran 90/95 Explained discussion of types in sections 2.5 and 2.6 for further information.

- Mat
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