Summary -

In this topic, we described about the Comp-2/Computation-2 with detailed example.

Specifies for internal floating-point items that are double precision. COMP-2 items are 8 bytes long. COMP-2 items can't have PICTURE clause.

COMP-2 allows VALUE clause with floating-point literal. COMP-2 allows signed floating-point item where the sign stores on leftmost bit.

COMP-2 stores the data in the format of mantissa and exponent. In this, mantissa is numeric value and exponent is the precision number.

In the 8 bytes, leftmost first bit to store sign, next 7 bits to store exponent and remaining 56 bits stores mantissa.

Below table represents the storage occupation based on the number of digits in PICTURE clause –

Digits in PICTURE clause Storage occupied
1 through 32 8 bytes (doubleword)

For example, 9.999 value required to store in data item which is declared as COMP-1. The data stores in the memory like 9999 * 10-3.

9.999 equal to 9999 * 10-3.

In the above, -3 is exponent value (stored in left most 12 bits) and 9999 is mantissa (stored in remaining 52 bits).

Practicle Example -

Code -

 IDENTIFICATION DIVISION.                                         
 PROGRAM-ID. COMP2.                                               
 ENVIRONMENT DIVISION.                                            
 DATA DIVISION.                                                   
 WORKING-STORAGE SECTION.                                        
 01 COMP2-NM              PIC 9(03) USAGE COMP-2 VALUE '256'.     
 PROCEDURE DIVISION.                                              
     DISPLAY 'COMPUTATION-2..'.                                   
     DISPLAY 'COMPUTATION2 - NUMERIC [9(01) - 9(32)]-> 8 BYTES '. 
     DISPLAY COMP2-NM.                                            
     STOP RUN.