Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compute Rounded 1

Status
Not open for further replies.

claudeb

Programmer
Nov 23, 2000
140
CA
Hello , how come that the value of A after computation is 185.07 instead of 184.92 ?
A PIC S9(9)V99 COMP-3.
B PIC S9(9)V99 COMP-3.
C PIC S9(6)V9(3) COMP-3.
D PIC S9(6)V9(3) COMP-3
A=00000000000 ; B=00030000000 ; C=000005810 ;D=000062000
COMPUTE A ROUNDED = A + B * ( 1 - C/ 1000.0 ) * D / 100000.00.
 
Hi Claude,

Compute has a problem with complex "equations" involving divide. Has something to do with work area decimal positions.

My advice: make a v999, don't round in the compute; add another compute AA rounded = A, where AA has pic ...v99. If that doesn't work add a few more decimal places to c & d.

BTW, any luck on your dump? How do you browse your O/P if you don't have SDSF? What do you use? Does it have edit capability? Can't understand why you cant find stmt# 3501.

Regards, Jack.
 
how nice of you to answer so quickly.
it was confirmed that there is no SDSF here. we have BimEdit, it has search options....but no statement 3501, beside GN=3501 witch links to a plan header of a policy (insurance compagny....). the policy was not active at that moment. i don't know if it is the source of the problem.
about the actual problem, i read the article in
and tried to follow the advice. thanks again
 
Claude, are you sure you're looking in the Compile Listing and not the dump listing. If you are using LIST/NOOFF you HAVE to have the line# that the dump list told you that the pgm abended at.
 
i recompiled the program just to make sure. there is no 3501 in column 1-6, or any generated code "3501".
i expect a lot of trouble if another abend like this one happens.
------------
for the precision problem, changing to v999 didn't help. i tried to change the order of operations, same thing. next step, i will multiply by 1.000000.
thanks
 
hi slade,
multiplying by 1.000000 solved my problem !!!
thanks again
 
Hi Claude,

Glad to see that you solved your compute problem. But that abend thing is driving me crazy. Could you send me via e-Mail the entire O/P from your compile run? I wonder if you're getting all the output you should.

You can get my e-address from the other newsgroup. Just look in one of my posts and click on the icon that has the "?"; that'll have my e-address.

Regards, Jack.

 
From past experience, I think it's a question of your calculation losing precision during the interim results. For example, C/1000 = 0.0581, but if the compiler keeps this result in A, you will lose precision there. Multiplying and dividing with this error just increases the error even more.
From my problem, it was the precision of the eventual target field that mattered, ie. A. I would give A a much larger decimal precision, perhaps at least 6 dps. The best way to sequence the calculation is to do the multiplying before dividing. I also find that putting explicit brackets into the calculations helps aid understanding AND ensures the correct sequence is carried out - sometimes what you think will happen will actually not if the compiler decides to do one step before another.
Hope this helps.
 
thanks yordaman
i just had another problem about precisions.
claudeb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top