View previous topic :: View next topic |
Author |
Message |
raja_here Beginner
Joined: 23 May 2007 Posts: 7 Topics: 2
|
Posted: Fri Feb 08, 2008 5:40 am Post subject: Usage COMP-2. |
|
|
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 |
|
 |
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Fri Feb 08, 2008 10:19 am Post subject: |
|
|
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 |
|
 |
CraigG Intermediate
Joined: 02 May 2007 Posts: 202 Topics: 0 Location: Viginia, USA
|
Posted: Fri Feb 08, 2008 12:26 pm Post subject: |
|
|
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 |
|
 |
raja_here Beginner
Joined: 23 May 2007 Posts: 7 Topics: 2
|
Posted: Sat Feb 09, 2008 6:52 am Post subject: |
|
|
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 |
|
 |
CraigG Intermediate
Joined: 02 May 2007 Posts: 202 Topics: 0 Location: Viginia, USA
|
Posted: Sat Feb 09, 2008 7:05 am Post subject: |
|
|
That's just the nature of floating point numbers, you could try using a comp-3 for A. |
|
Back to top |
|
 |
raja_here Beginner
Joined: 23 May 2007 Posts: 7 Topics: 2
|
Posted: Sat Feb 09, 2008 9:01 am Post subject: |
|
|
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 |
|
 |
|
|