View previous topic :: View next topic |
Author |
Message |
seekaysk Beginner
Joined: 31 Aug 2007 Posts: 49 Topics: 15
|
Posted: Thu Jan 10, 2008 12:15 pm Post subject: Multiplication and Division of large values |
|
|
Hi,
I have a basic query which i tried to find a lot but could not. If any of you could please help me.
A = 212600.840 PIC S(15)V9(3) COMP-3
D = 0.3945723 PIC S(5)V9(7) COMP-3
final = PIC S(5)V9(7) COMP-3
During the processing of my program, my calculation goes:
final = (A * D) / A
In this case, the value should come as exactly D. But it differs at the 7th decimal and value of final comes to be 0.3945722
(Please note : You may have doubts that why to multiply and divide the same factor. there are many such programs using the processing above which have different logic and hence the mathematical calculation shown above has to be the same. this cannot be changed)
I thought of using something like
final = (float(A * D)) / A
but cobol doesn't accept float.
If you are aware, can you please let me know if there's anything like FLOAT so that numerator does not get truncated to 7 decimals.
fyi. I cannot change the compiler options. It's through change management tool.
thanks for your help. _________________ Thanks. |
|
Back to top |
|
 |
seekaysk Beginner
Joined: 31 Aug 2007 Posts: 49 Topics: 15
|
Posted: Thu Jan 10, 2008 1:35 pm Post subject: |
|
|
Hi All,
I forgot to mention that I do know of two possiblities to solve it. However there are defects into it.
1) final ROUNDED = (A * D) / A --> this is very risky and to solve one problem it may create another. so I cannot use this.
2) declare FINAL1 as PIC S9(5)V9(15) and
final1 = (A * D) / A
MOVE FINAL1 TO FINAL
where final is defined as S9(5)V9(7). ---> but this is a long solution. (Although not so long). I just wanted to know if there can be anything like a FLOAT or DECIMAL so that things become easy.
thanks for your patience. _________________ Thanks. |
|
Back to top |
|
 |
CraigG Intermediate
Joined: 02 May 2007 Posts: 202 Topics: 0 Location: Viginia, USA
|
Posted: Thu Jan 10, 2008 2:00 pm Post subject: |
|
|
seekaysk wrote: | Hi All,
I forgot to mention that I do know of two possiblities to solve it. However there are defects into it.
1) final ROUNDED = (A * D) / A --> this is very risky and to solve one problem it may create another. so I cannot use this.
2) declare FINAL1 as PIC S9(5)V9(15) and
final1 = (A * D) / A
MOVE FINAL1 TO FINAL
where final is defined as S9(5)V9(7). ---> but this is a long solution. (Although not so long). I just wanted to know if there can be anything like a FLOAT or DECIMAL so that things become easy.
thanks for your patience. |
Your option 2 seems to be the best since you are forcing cobol to use greater precision then it would normally use. Since (A * D) / A is pretty much a waste anyways adding the extra move shouldn't be a problem. |
|
Back to top |
|
 |
seekaysk Beginner
Joined: 31 Aug 2007 Posts: 49 Topics: 15
|
Posted: Thu Jan 10, 2008 2:36 pm Post subject: |
|
|
Thanks Craig.
I have temp used this and continued along. I just wanted to know if there exists anything simpler not a part of my basic knowledge.
thanks again. _________________ Thanks. |
|
Back to top |
|
 |
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Sat Jan 12, 2008 6:12 pm Post subject: |
|
|
I don't get it. Why are you multiplying D by A, then dividing by A? Why not:
final ROUNDED = D
BTW, why is there no verb in the stmt? i.e. COMPUTE. Am I missing something or is this NOT cobol? _________________ Regards, Jack.
"A problem well stated is a problem half solved" -- Charles F. Kettering |
|
Back to top |
|
 |
|
|