View previous topic :: :: View next topic

Author 
Message 
saurabh39 Warnings : 1 Active User
Joined: 11 Apr 2008 Posts: 144 Location: Jamshedpur




Hi All,
The post is refering to below link 
Link
For division it says integer digits in quotient will be i2 + d1. Where i2 is number of digits in divisor and d1 is number of decimal places in dividend.
I was trying to find out if i2 + d1 will be sufficient for quotient or not. Can any one give me a lead on how to approach this problem.[/url 

Back to top 




Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark




The quotient would be greater than the dividend when the divisor is less than zero.
Therefore the smallest divisor that can be represented is a 1 in the last decimal place which is the same as multiplying with 10 raised to the power of the number of decimals.
Example
40 / 0.01 = 4000 (2 digits + 2 dec. digit = 4 digit in quotient)
40 / 0.001 = 40000 (2 digits + 3 dec. digit = 5 digits in quotient) 

Back to top 


saurabh39 Warnings : 1 Active User
Joined: 11 Apr 2008 Posts: 144 Location: Jamshedpur




HI Kjeld,
Quote: 
The quotient would be greater than the dividend when the divisor is less than zero 
I think you meant less than one and greater than zero. Less than zero will just change the sign. Number of digits will remain same.
As for the example, you added integer part of numerator and decimal part of denominator. But manual says just the ooposite. 

Back to top 


Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8218 Location: Dubuque, Iowa, USA




First, unless you have PIC clauses for the two variables, you cannot know i2 or i1 or d2 or d1. So your first step is to actually select some PIC clauses to run through the rules.
Second, if IBM had gotten the arithmetic precision rules wrong, do you not think that someone over the last 47 years of using the various COBOL compilers on IBM systems might have noticed and said something?
Third, why do you think there is that little phrase ON SIZE ERROR in the various COBOL arithmetic verb syntax diagrams? If you think there is some chance of a problem, you should use the phrase. 

Back to top 


Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark




saurabh39 wrote: 
HI Kjeld,
Quote: 
The quotient would be greater than the dividend when the divisor is less than zero 
I think you meant less than one and greater than zero. Less than zero will just change the sign. Number of digits will remain same.
As for the example, you added integer part of numerator and decimal part of denominator. But manual says just the ooposite. 
You are absolutely right about the interval  I meant less than 1 instead of less than zero.
I think you got it wrong for the operands involved in division. Read Appendix 1.1.1 once more. The sequence of operators in the DIVIDE statement is reversed compared to COMPUTE division syntax with the operator /, at least when DIVIDE INTO syntax is used. 

Back to top 


saurabh39 Warnings : 1 Active User
Joined: 11 Apr 2008 Posts: 144 Location: Jamshedpur




Thanks Kjeld for pointing out, I got the operator sequence wrong.
Suppose I have a compute statement which involves many operand, include the one in given  (WSA/100)
WSA has been defined as S9(04)V9(5) COMP3.
Since the expression was in a bracket, so it will be calculated first and stored in intermediate result.
Since intermediate result pic clause will have decimal digits from denominator, so in this case what will be the number of decimal digits for 100. 

Back to top 


Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark




The manual says:
Quote: 
(d2  d1) or dmax, whichever is greater

so go figure...
The intermediate result precision is not depending on whether you have put the expression in brackets or not, and it makes no sense to bracket a single computation out of it context.
My good matemathical sense tells me that in order not to loose any precision in above example the result should have (at least) 7 decimal places. 

Back to top 


saurabh39 Warnings : 1 Active User
Joined: 11 Apr 2008 Posts: 144 Location: Jamshedpur




The question I had was.....will 100 be changed to compliment the data type of numerator, or will compiler understand it as a number with 3 integer digit and zero decimal digits.
Quote: 
and it makes no sense to bracket a single computation out of it context. 
Actually the expression i gave was part of bigger equation, and thats why it was put in brackets.
Quote: 
My good matemathical sense tells me that in order not to loose any precision in above example the result should have (at least) 7 decimal places. 
But in our case, the value during intermediate result calculation was truncated to 5 decimal digits and thus we got a wrong result. 

Back to top 


Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 1951 Location: UK




If you cannot get the right intermediate results by adjusting parms and parameters then you will have to split the computtion up into its individual components.
E.g.
instead of:
answer = a * b * c
do:
temp = a * b
answer = temp * c 

Back to top 


Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8218 Location: Dubuque, Iowa, USA




100 is a numeric literal with no decimal places  hence it is defined as an integer. These terms are both defined in the Glossary for the COBOL Programming Guide  so you can determine the intermediate results of your calculation. The general rule of thumb is to do multiplication before division since you may otherwise lose decimal digits you want to keep by doing the division first. 

Back to top 


