MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Usage COMP-2.

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> CICS and Middleware
View previous topic :: View next topic  
Author Message
raja_here
Beginner


Joined: 23 May 2007
Posts: 7
Topics: 2

PostPosted: Fri Feb 08, 2008 5:40 am    Post subject: Usage COMP-2. Reply with quote

Hi,

Please find the problem scenario...

Variable A of PIC clause COMP-2. (value 3.871875)
Variable B of PIC clause PIC S9(13)V9(5) COMP-3. (value 52000)
Variable C of PIC clause PIC S9(3)v9(12) COMP-3. (value 1)
Variable D of PIC clause PIC S9(16)V9(2) COMP-3.

Compute A rounded = (A * B * C) / 100
Multiply A by 1 giving D rounded.

This should produce 2013.38.. But producing 2013.37.. Please explain why is it so.. Also, what can we do to make D 2013.38? Your help in this would be greatly appreciated. Thanks in advance for your help.
_________________
Thanks,
Raja P.
Back to top
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Fri Feb 08, 2008 10:19 am    Post subject: Reply with quote

I don't have access to a mainframe, but my guess is that you are losing precision of an intermediate result. You could try using the ARITH(EXTEND) compiler option or try
Code:
compute E rounded = A * B * C (where E is PIC S9(15)V999 COMP-3)
divide E by 100
multiply E by 1 giving D rounded
Either way a little experimenting should get you what you want. See Programming Guide for rules on the precision of intermediate results. They are not what you might expect (or hope for).
P.S. This probably belongs in the Application Programming Forum, not CICS.
_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
CraigG
Intermediate


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Fri Feb 08, 2008 12:26 pm    Post subject: Reply with quote

What is the value in A after the COMPUTE? Remember that COMP-1 and COMP-2 (FLOATING POINT) are not exact values.
Back to top
View user's profile Send private message
raja_here
Beginner


Joined: 23 May 2007
Posts: 7
Topics: 2

PostPosted: Sat Feb 09, 2008 6:52 am    Post subject: Reply with quote

yes.. comp-2 here also didn't contain the exact value..
the value of A was 2013.374999999998.. please tell how this value was obtained..

Craig/Terry,
Thanks for your immediate responses.

Terry,
the solution you suggested resolves the problem I said.. But it's hitting some good values too.. Thanks again.
_________________
Thanks,
Raja P.
Back to top
View user's profile Send private message
CraigG
Intermediate


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Sat Feb 09, 2008 7:05 am    Post subject: Reply with quote

That's just the nature of floating point numbers, you could try using a comp-3 for A.
Back to top
View user's profile Send private message
raja_here
Beginner


Joined: 23 May 2007
Posts: 7
Topics: 2

PostPosted: Sat Feb 09, 2008 9:01 am    Post subject: Reply with quote

Oh.. I could not avoid usage of COMP-2 since we want the result to be more precise. We used COMP-2 since it can hold 16+2, 9+9, etc.. As usual, first integer part needs to be more precise, then the decimal part. I have splitted the integer and decimal part and added. The results are convincing for a small run.. Let us see.. Again, Thanks a lot!
_________________
Thanks,
Raja P.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> CICS and Middleware All times are GMT - 5 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


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group