PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Real & Integer

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



Joined: 27 Jul 2004
Posts: 3

PostPosted: Mon Apr 04, 2005 8:38 am    Post subject: Real & Integer Reply with quote

I'm working some legacy code, and just recently realized that there are many places in the code where integers are used where reals should be. e.g. :

Code:

real::varA, varB
varA =  10^18
varB =  10^18.0
print *, varA
print *, varB


yeilds:

Code:

0
1E-18


The above is just an example, but the original authors of the code meant for varA to be 1E-18 and not zero. And, this is affecting the results of the program.

Is there any compiler switch or any other way to either a) automatically cast integer constants up to reals ( e.g. 18 -> 18.0) or b) at least stop compilation with an error so that I can manually correct these lines?

Thanks.
Back to top
View user's profile
mkcolg



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

PostPosted: Mon Apr 04, 2005 11:06 am    Post subject: Reply with quote

HI LKP,

Just to clarify, I think you meant "10**18" not "10^18" since "10^18" is not legal syntax. Also, you should get a negative value for varA, not 0.

What's happening is that the integer constant "10**18" is too big for an INTEGER*4, which is the default, and thus results in a negative value. This negative value is then cast to a REAL and assigned to varA. For this test case you can compile with "-i8" which changes the default integer kind to 8, and will be big enough to hold "10**18". Of course, using "-i8" might cause other problems since all "INTEGER" variables will now be "INTEGER*8", but it's worth a try.

Hope this helps,
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