Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
saurabh39
Warnings : 1

Active User

Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

 Posted: Wed Apr 06, 2011 10:52 am    Post subject: Number of digits in quotient 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

Kjeld

Active User

Joined: 15 Dec 2009
Posts: 365
Location: Denmark

 Posted: Wed Apr 06, 2011 1:58 pm    Post subject: 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)
saurabh39
Warnings : 1

Active User

Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

Posted: Wed Apr 06, 2011 5:35 pm    Post subject: Reply to: Number of digits in quotient

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.
Robert Sample

Global Moderator

Joined: 06 Jun 2008
Posts: 8280
Location: Dubuque, Iowa, USA

 Posted: Wed Apr 06, 2011 6:14 pm    Post subject: 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.
Kjeld

Active User

Joined: 15 Dec 2009
Posts: 365
Location: Denmark

Posted: Wed Apr 06, 2011 7:48 pm    Post subject: Re: Reply to: Number of digits in quotient

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.
saurabh39
Warnings : 1

Active User

Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

 Posted: Wed Apr 06, 2011 8:48 pm    Post subject: Reply to: Number of digits in quotient 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 - (WS-A/100) WS-A has been defined as S9(04)V9(5) COMP-3. 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.
Kjeld

Active User

Joined: 15 Dec 2009
Posts: 365
Location: Denmark

Posted: Fri Apr 08, 2011 4:20 am    Post subject:

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.
saurabh39
Warnings : 1

Active User

Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

Posted: Mon Apr 11, 2011 2:46 pm    Post subject: Reply to: Number of digits in quotient

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.
Nic Clouston

Global Moderator

Joined: 10 May 2007
Posts: 2002
Location: UK

 Posted: Mon Apr 11, 2011 2:59 pm    Post subject: 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
Robert Sample

Global Moderator

Joined: 06 Jun 2008
Posts: 8280
Location: Dubuque, Iowa, USA

 Posted: Mon Apr 11, 2011 2:59 pm    Post subject: 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.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Repeat Sequence Number Until change i... rahulabvp DFSORT/ICETOOL 6 Thu Mar 29, 2018 12:51 pm add sequence number for duplicate rec... SRUTHI DRAVIDAMANI COBOL Programming 11 Thu Feb 22, 2018 5:37 pm PARSE GDG name to separate generation... Abid Hasan SYNCSORT 2 Sun Feb 11, 2018 3:40 pm Increment number for every group of r... srajendran2 DFSORT/ICETOOL 7 Thu Nov 09, 2017 10:31 pm Profile changed to NUMBER ON STD (fro... Martylin TSO/ISPF 1 Thu Aug 03, 2017 9:14 am

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us