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 

Multiplication and Division of large values

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
seekaysk
Beginner


Joined: 31 Aug 2007
Posts: 49
Topics: 15

PostPosted: Thu Jan 10, 2008 12:15 pm    Post subject: Multiplication and Division of large values Reply with quote

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
View user's profile Send private message
seekaysk
Beginner


Joined: 31 Aug 2007
Posts: 49
Topics: 15

PostPosted: Thu Jan 10, 2008 1:35 pm    Post subject: Reply with quote

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
View user's profile Send private message
CraigG
Intermediate


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

PostPosted: Thu Jan 10, 2008 2:00 pm    Post subject: Reply with quote

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
View user's profile Send private message
seekaysk
Beginner


Joined: 31 Aug 2007
Posts: 49
Topics: 15

PostPosted: Thu Jan 10, 2008 2:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
slade
Intermediate


Joined: 07 Feb 2003
Posts: 266
Topics: 1
Location: Edison, NJ USA

PostPosted: Sat Jan 12, 2008 6:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming 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