View previous topic :: View next topic
|
Author |
Message |
danish Currently Banned New User
Joined: 13 Feb 2008 Posts: 3 Location: pune
|
|
|
|
hi frnds,
in my calaculator program which i am coding in cobol i have to calaulate
22/7 and user has the liberty to calcaulate the as many decimal points he wants as:
22/7 and if he spcified 3 so it should be 22/7=3.142 after decimal 3 digits if he is passing 10,20,30 so those no of digits should come after decimal point
danish |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Do you know how to do 'long division'?
For the dynamic-ness you want, you will need to to he calculation like you would do long division, guess & subtract over and over again.... |
|
Back to top |
|
|
danish Currently Banned New User
Joined: 13 Feb 2008 Posts: 3 Location: pune
|
|
|
|
Please can some one put one example for that one?????????? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
danish,
what is your input? how do you receive the input?
apparently, you have input for a mulitplicand and a multiplier and number of decimal positions?
the product definition is based on decimal positions and significant digits.
you mentioned 10,20,30......... unless you change compiler options (for this homework program i would not bother) you only have 18 positions.
so if you have 10 decimal positions, you only have room for 8 significant digits. plus a sign.
so you are going to have to limit the number of decimal positions.
and depending upon the number of decimal positions, you could use an evaluate to decide what the product definition will be.
prod-def-1 pic s9(17)v9.
prod-def-2 pic s9(16)v99. ....... |
|
Back to top |
|
|
danish Currently Banned New User
Joined: 13 Feb 2008 Posts: 3 Location: pune
|
|
|
|
so can't we take more than 18 decimal places |
|
Back to top |
|
|
priya
Moderator
Joined: 24 Jul 2003 Posts: 568 Location: Bangalore
|
|
|
|
We can. But you cant understand, even if we explain to you now!
Search the forums, then come back here, after you learned about compiler Options, IBM & Enterprice cobol enhancements & external floating point literals. |
|
Back to top |
|
|
star_dhruv2000
New User
Joined: 03 Nov 2006 Posts: 87 Location: Plymouth, MN USA
|
|
|
|
Hi,
Normally Compliers resist to use maximum of 18 digit number.
But if you use ARITH(EXTEND) compiler option, maximum number of digit positions that you can specify in the PICTURE clause for packed-decimal, external-decimal, and numeric-edited data items is raised from 18 to 31.
Cheers! |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
Why bother with the calculation of 22/7 each time. It is an approximation at best, like every other PI value that you terminate. Grab the first 31 digits and put them into a constant. Then truncate that number to the size you need and use NUMVAL(?) (is that the right funtion) to convert it to a decimal value with.
WS-PI PIC X(32) VALUE '3.1415926535897932384626433832' |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
Anything beyond the 30 positions after the decimal and you will have to implement it yourself in some fashion. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Do a little bit of web reading on long decimal numbers ( with arbitrary number of digits )
starting from
http://www2.hursley.ibm.com/decimal/
very rewarding from a theoretical point of view |
|
Back to top |
|
|
|