HP 3000 Manuals

COMPUTE Statement [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

COMPUTE Statement 

The COMPUTE statement evaluates an arithmetic expression (Refer to
Chapter 8 , under "Arithmetic Expressions"), and assigns the result to
one or more data items. 

Syntax 

	       Click here to view figure.
            

Parameters 

identifier-1            refers to either an elementary numeric, or an
                        elementary numeric-edited data item.

arithmetic-expression   any valid COBOL arithmetic expression.

The ROUNDED and SIZE ERROR and  NOT ON SIZE ERROR phrases are described
in Chapter 8 , as are multiple results and other information
pertaining to arithmetic statements.

The COMPUTE statement allows you to combine arithmetic operations without
the restrictions on composites of operands or receiving data items
imposed by the arithmetic statements ADD, SUBTRACT, MULTIPLY, and DIVIDE.

When the COMPUTE statement executes, the arithmetic expression is
evaluated, and all of the identifiers to the left of the equal sign are
assigned the value of the result.  Rounding is done where specified and
necessary.  For example,

     COMPUTE DAILY-RTE-1, DAILY-RTE-2 = (INT - RTE / 360) * DAYS
         ON SIZE ERROR PERFORM RATE-ERROR-RTNE.

In the above statement, a daily interest rate is calculated, and the
results are stored in the two data items, DAILY-RTE-1 and DAILY-RTE-2.
If a size error occurs, no data is stored in the two receiving data items
and the error handler, RATE-ERROR-RTNE, is performed.

Calculation of Intermediate Results 

The following description presents the conceptual compiler algorithms for
determining the size and number of decimal places reserved for
intermediate results.  This information is provided since the
manipulations performed on the intermediate results are not always
obvious.  These algorithms apply to all arithmetic and compute
statements. 

The following abbreviations are used:

d                     number of decimal places carried for an
                      intermediate result.

dmax                  maximum number of decimal places defined for any
                      operand in a particular statement including the
                      result.

op1                   first operand in a generated arithmetic statement.

op2                   second operand in a generated arithmetic statement.

d1,d2                 number of decimal places defined for op1  or op2,
                      respectively.

ir                    intermediate result field obtained from the
                      execution of a generated arithmetic statement or
                      operation.  Ir1, ir2, etc., represent successive
                      intermediate results.  Successive intermediate
                      results may have the same location.

Most arithmetic statements generate intermediate results except for
simple cases, (for example, single pair of operands) where the result can
be stored without decimal point alignment or conversion. 

The compiler treats the statement as a succession of operations.  For
example, consider the following statement:

     COMPUTE Y = A + B * C - D / E + F ** G

The above COMPUTE statement is replaced by the following:

MULTIPLY C      BY B            Yielding ir1

ADD ir1         TO A            Yielding ir2

DIVIDE D        BY E            Yielding ir3

SUBTRACT ir3    FROM ir2        Yielding ir4

RAISE F         TO THE POWER G  Yielding ir5

ADD ir4         TO ir5          Yielding ir6

STORE ir6       TO Y

The compiler determines the maximum value that the ir can contain by
performing the statement in which the ir occurs.

   *   If an operand in this statement is a data name, the value for the
       data name is equal to the numerical value of the PICTURE for the
       data name (for example, PICTURE 9V99 has the value 9.99).

   *   If an operand is a literal, the literal's actual value is used,
       except in case of DIVIDE.

   *   If an operand is an intermediate result, the value determined for
       the intermediate result in a previous arithmetic operation is
       used.

   *   If the operation is division:

          *   If op2 is a data name, the value used for op2 is the
              minimum nonzero value of the digit in the PICTURE for the
              data name (for example, PICTURE 9V99 has the value 0.01).

          *   If op2 is an intermediate result, the intermediate result
              is treated as though it had a PICTURE, and the minimum
              nonzero value of the digits in this PICTURE is used.

When the maximum value exceeds the machine specific limit, a warning
(#050) is generated and the maximum size is set at that limit.  For
limitations on arithmetic expressions refer to "MPE XL System
Dependencies" in Appendix H  for more information.

The number of decimal places contained in an ir is calculated as:

Operation             Decimal Places                                                                                                 

+ or -                d1 or d2, whichever is greater

*                     d1 + d2 

/                     d1-d2 or dmax, whichever is greater

**                    dmax 

[REV BEG]


NOTE When any operand is an IEEE floating point (from the result of a COBOL function), the resulting intermediate data item is also IEEE floating point. The intermediate floating point data items always have 15 digits of precision.
[REV END]


MPE/iX 5.0 Documentation