Re: Max integer in an 8 byte COMP field?




Folks,
I thankyou kindly - I got the answers I needed.
And an education too.
Graham


On Fri, 20 Apr 2007 11:43:36 -0400, Graham Hobbs <ghobbs@xxxxxxxxxxx>
wrote:

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

.