Re: Max integer in an 8 byte COMP field?



Tried this with MF SE 4 at customer site, interesting -
cob -u -C NOTRUNC ltest.cob
cobrun ./ltest
PIC 9(18) COMP.
611686018427387904
223372036854775808
446744073709551615
PIC S9(18) COMP.
+611686018427387904
-223372036854775808
-000000000000000001
PIC 9(18) COMP-5.
611686018427387904
223372036854775808
446744073709551615
PIC S9(18) COMP-5.
+611686018427387904
-223372036854775808
-000000000000000001

(with the correction below)

"Roger While" <simrw@xxxxxxxxxxxx> schrieb im Newsbeitrag
news:f0cgvt$bpi$01$1@xxxxxxxxxxxxxxxxxxxx
And nobody spotted the mistake :-)
Should be -
WORKING-STORAGE SECTION.
01 rc1 pic 9(18) comp.
01 rc2 pic s9(18) comp.
01 rc3 pic 9(18) comp-5.
01 rc4 pic s9(18) comp-5.

Revised results -
simlinux:~ # cobc -x -std=mf ltest.cob
simlinux:~ # ./ltest
PIC 9(18) COMP.
04611686018427387904
09223372036854775808
18446744073709551615
PIC S9(18) COMP.
+04611686018427387904
+00000000000000000000
+09223372036854775807
PIC 9(18) COMP-5.
04611686018427387904
09223372036854775808
18446744073709551615
PIC S9(18) COMP-5.
+04611686018427387904
+00000000000000000000
+09223372036854775807
simlinux:~ # cobc -x -std=cobol2002 ltest.cob
simlinux:~ # ./ltest
PIC 9(18) COMP.
000000000000000000
000000000000000000
000000000000000000
PIC S9(18) COMP.
+000000000000000000
+000000000000000000
+000000000000000000
PIC 9(18) COMP-5.
611686018427387904
223372036854775808
446744073709551615
PIC S9(18) COMP-5.
+611686018427387904
+000000000000000000
+223372036854775807

"Roger While" <simrw@xxxxxxxxxxxx> schrieb im Newsbeitrag
news:f0atam$rlj$02$1@xxxxxxxxxxxxxxxxxxxx
simlinux:~ # cat ltest.cob
IDENTIFICATION DIVISION.
PROGRAM-ID. LTEST.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 rc1 pic 9(18) comp.
01 rc2 pic s9(18) comp-5.
01 rc3 pic 9(18) comp.
01 rc4 pic s9(18) comp-5.
PROCEDURE DIVISION.
display "PIC 9(18) COMP."
compute rc1 = 2 ** 62.
display rc1.
compute rc1 = 2 ** 63.
display rc1.
compute rc1 = 2 ** 64 - 1.
display rc1.
display "PIC S9(18) COMP."
compute rc2 = 2 ** 62.
display rc2.
compute rc2 = 2 ** 63.
display rc2.
compute rc2 = 2 ** 64 - 1.
display rc2.
display "PIC 9(18) COMP-5."
compute rc3 = 2 ** 62.
display rc3.
compute rc3 = 2 ** 63.
display rc3.
compute rc3 = 2 ** 64 - 1.
display rc3.
display "PIC S9(18) COMP-5."
compute rc4 = 2 ** 62.
display rc4.
compute rc4 = 2 ** 63.
display rc4.
compute rc4 = 2 ** 64 - 1.
display rc4.
STOP RUN.

With OC -
simlinux:~ # cobc -x -std=mf ltest.cob
simlinux:~ # ./ltest
PIC 9(18) COMP.
04611686018427387904
09223372036854775808
18446744073709551615
PIC S9(18) COMP.
+04611686018427387904
+00000000000000000000
+09223372036854775807
PIC 9(18) COMP-5.
04611686018427387904
09223372036854775808
18446744073709551615
PIC S9(18) COMP-5.
+04611686018427387904
+00000000000000000000
+09223372036854775807

Note, need the std=mf otherwise result would be default
be not calculated if precision exceeds pic definition.

Interesting -
MF SE 2.2 -
simlinux:~ # cob -u -C notrunc ltest.cob
simlinux:~ # cobrun ltest
PIC 9(18) COMP.
611686018427387904
223372036854775808
446744073709551615
PIC S9(18) COMP.
+611686018427387904
-223372036854775808
-000000000000000001
PIC 9(18) COMP-5.
611686018427387904
223372036854775808
446744073709551615
PIC S9(18) COMP-5.
+611686018427387904
-223372036854775808
-000000000000000001

What is correct I will leave the Gurus to work out :-)

Roger

"Graham Hobbs" <ghobbs@xxxxxxxxxxx> schrieb im Newsbeitrag
news:j9nh23lfuelrdtvktcjh84ugd6s9kjh51u@xxxxxxxxxx
Hello,

I can't figure this out.
Am trying to find the largest integer that will fit inside a 'comp'
field of 8 bytes (64 bits).
Below is the compiler output followed by execution results.
I tried with both signed and unsigned COMP fields.

I can understand why exponents of 64 and 65 go to zero (I think) but:

1. why at 62 does the displayed result have 19 digits (when my Cobol
manuals tell me 18 is the maximum).
2. same for 63, but additionally, why has it gone negative.
3. I still don't know what the largest integer can be.

Any ideas please, thanks.

Graham Hobbs

..............................................

Compiler (VisualAge Cobol V2.2) output:

000091 05 RES1 PIC 9(18) COMP. 8(0000221)
000092 05 RES2 PIC S9(18) COMP. 8(0000229)


000115 DISPLAY '--------------------------------'
000116 COMPUTE RES1 = 2 ** 62 DISPLAY ' RES1=' RES1
000117 COMPUTE RES1 = 2 ** 63 DISPLAY ' RES1=' RES1
000118 COMPUTE RES1 = 2 ** 64 DISPLAY ' RES1=' RES1
000119 COMPUTE RES1 = 2 ** 65 DISPLAY ' RES1=' RES1
000120 DISPLAY '--------------------------------'
000121 COMPUTE RES2 = 2 ** 62 DISPLAY ' RES2=' RES2
000122 COMPUTE RES2 = 2 ** 63 DISPLAY ' RES2=' RES2
000123 COMPUTE RES2 = 2 ** 64 DISPLAY ' RES2=' RES2
000124 COMPUTE RES2 = 2 ** 65 DISPLAY ' RES2=' RES2
000125 DISPLAY '--------------------------------'

Results:
-------------------------------
RES1=4611686018427387904
RES1=-9223372036854775808
RES1=0000000000000000000
RES1=0000000000000000000
-------------------------------
RES2=4611686018427387904
RES2=-9223372036854775808
RES2=0000000000000000000
RES2=0000000000000000000
-------------------------------
Cheers

--
Posted via a free Usenet account from http://www.teranews.com







.



Relevant Pages