Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Number of digits in quotient

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Wed Apr 06, 2011 10:52 am    Post subject: Number of digits in quotient
Reply with quote

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

Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Wed Apr 06, 2011 1:58 pm    Post subject:
Reply with quote

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
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

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

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

Global Moderator


Joined: 06 Jun 2008
Posts: 7912
Location: Bellevue, IA

PostPosted: Wed Apr 06, 2011 6:14 pm    Post subject:
Reply with quote

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

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

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

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
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Wed Apr 06, 2011 8:48 pm    Post subject: Reply to: Number of digits in quotient
Reply with quote

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.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Fri Apr 08, 2011 4:20 am    Post subject:
Reply with quote

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
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

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

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

Global Moderator


Joined: 10 May 2007
Posts: 1714
Location: UK

PostPosted: Mon Apr 11, 2011 2:59 pm    Post subject:
Reply with quote

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

Global Moderator


Joined: 06 Jun 2008
Posts: 7912
Location: Bellevue, IA

PostPosted: Mon Apr 11, 2011 2:59 pm    Post subject:
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to get the remainder and quotient... vnktrrd DFSORT/ICETOOL 2 Mon Oct 31, 2016 10:59 am
No new posts Sequence number add in SORT pshongal SYNCSORT 3 Fri Sep 02, 2016 3:32 pm
No new posts Casting a Binary Number to Numeric in... Bob Steinkraus Java & MQSeries 6 Tue Aug 09, 2016 5:58 pm
No new posts GDG vsersion number change Raghu navaikulam JCL & VSAM 5 Fri May 27, 2016 4:49 pm
No new posts CPU time Vs Number of records Nileshkul JCL & VSAM 5 Mon May 09, 2016 4:05 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us