Skip to main content

Problem:

A non-COBOL program will be passing parameters to a COBOL program, and some of the parameters will be floating point items.

Resolution:

COMP-1 and COMP-2 are "floating point" numeric USAGE data items. They are defined as follows:

       77  single usage comp-1.

       77  double usage comp-2.

COMP-1 is a "single precision" floating point item. COMP-2 is a "double precision" floating point item. COMP-1 items use four (4) bytes of storage. COMP-2 items use eight (8) bytes of storage. The COMP-2 item's greater precision is a consquence of the additional memory that allows support of larger numbers.

These items can be initialized with a "floating point" literal. The literal format is unique.

             [sign] mantissa E [sign] exponent

The "sign" ( /-) preceding the mantissa and exponent are optional. When omitted, the signs are assumed to be positive. The mantissa is a fraction and is preceded by a decimal point (.). The mantissa can contain between 1 and 16 digits. The exponent is a one or two digit whole number. The "E" separates the mantissa and exponent. Here are a couple examples.

       77  single usage comp-1 value .12345678E 5.

       77  double usage comp-2 value .123456789E 5.

The sign of the exponent determines the direction in which the decimal point of the mantissa will move. A positive exponent will move the decimal point to the right. A negative exponent will move the decimal point to the left.

The magnitude of a floating-point literal value must fall between 0.54E-78 and 0.72E 76. For values outside this range, a diagnostic will be produced and the value will be replaced by 0 or 0.72E 76 respectively. You must not use a floating-point literal when an integer literal is required.

Check and Animate this small program monitoring the data items being processed.

      $set Ans85 Mf"10" NoOsvs NoVsc2 NoQual NoAlter DefaultByte"00"

       working-storage section.

       77  single                   usage comp-1 value .12345678E 5.

       77  single2                  usage comp-1 value .12345678E-5.

       77  double                   usage comp-2 value .123456789E 5.

       77  decimal  pic s9(9)v9(9)  usage comp-3.

       77  decimal2 pic z(9).9(9)-  usage display.

       procedure division.

           move single     to decimal

           move single2    to decimal

           move double     to decimal

           move decimal    to decimal2

           display single ' ' double

           display decimal ' ' decimal2

           stop run.

In this example the "decimal" item is defined as COMP-3. Other numeric usages, such as COMP,

COMP-5, COMP-X and DISPLAY, would work as well.

Single, double and integer data types are common to many programming languages. COBOL is unique in having a virtual decimal (999V99) numeric data item definition. Using floating point as an alternative may require careful attention to rounding.

Attachments:

2098565.cbl

Old KB# 7083