View previous topic :: View next topic
|
Author |
Message |
garv_fundu Warnings : 1 New User
Joined: 02 Nov 2006 Posts: 22
|
|
|
|
Hi all,
Why exactly do we declare a variable as comp-3?
Is there any specific reason or advantage in doing so?
How can it serve the purpose if the variable is a counter variable?
Kindly clarify.
[/u] |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Comp-3 is packed decimal, one of the mainframe native modes of arithmetic.
Declaring a variable as comp-3 (rather than display) allows arithmetic to be performed without conversation.
Actually, depending on what the counter is used for, comp might be more efficient. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
Whereas COMP may be more efficient than COMP-3, reading a COMP-3 value in hex is usually easier than reading COMP in hex. Human efficiency and ease may be more important than machine efficiency. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Would you believe conversion<g>?
Quote: |
Declaring a variable as comp-3 (rather than display) allows arithmetic to be performed without conversation.
|
Quote: |
Whereas COMP may be more efficient than COMP-3, reading a COMP-3 value in hex is usually easier than reading COMP in hex. Human efficiency and ease may be more important than machine efficiency.
|
With the mainframe, comes a set of "packed decimal" instructions. These are designed for "business arithmetic" - calculating and showing edited things like quantities and dollars. To get a value to a zz,zzz,zz9.99- field, the underlying assembler will prepare the edited value by first staging the value to a packed-decimal field (if it is not already in packed decimal format), then "edit"ing it into the target field.
While comp may save a bit of storage, it often will not use less machine cycles (which few care about these days. . .). |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
dick scherrer wrote: |
Would you believe conversion<g>? |
Grumble, grumble
Dang spellchecker, do what I mean, not what I say!.....grin...... |
|
Back to top |
|
|
cobolunni
Active User
Joined: 07 Aug 2006 Posts: 127 Location: kerala,india
|
|
|
|
Actually COMP 3 is used in case we had a signed number in comp3 each 2 digit will take 1 byte and the rightmost byte will contain only one digit plus the sign. So there is a reserved place for sign in COMP3 it will avoid the use of extra one byte for sign |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
cobolunni wrote: |
there is a reserved place for sign in COMP3 it will avoid the use of extra one byte for sign |
COMP3 only needs an extra half byte for its sigh while COMP gets by with one bit..... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hmmmm. . . .
Quote: |
COMP3 only needs an extra half byte for its sigh while COMP gets by with one bit... |
Long sigh . . . . ?
Quote: |
Grumble, grumble
Dang spellchecker, do what I mean, not what I say!.....grin...... |
|
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
dick scherrer wrote: |
Long sigh . . . . ? |
Well, they almost look the same....grin.... Heck with my fat fingers what do you expect
Quote: |
Grumble, grumble
Dang spellchecker, do what I mean, not what I say!.....grin...... |
[/quote] |
|
Back to top |
|
|
|