ILE COBOL Language Reference


Compiler Calculation of Intermediate Results

The number of integer places in an ir is calculated as follows:

The compiler first determines the maximum value that the ir can contain by assigning a numerical value to each of the operands used to generate the ir, and determining the value that would result from the operation.

Once the maximum value of the ir has been determined by the above procedures, i is set equal to the number of integers in the maximum value.

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

Table 42. Determining the Precision of an Intermediate Result

Operation Integer Places Decimal Places
+ or - (i1 or i2) + 1, whichever is greater d1 or d2, whichever is greater
* i1 + i2 d1 + d2
/ i1 + d2 (d2 - d1) or dmax, whichever is greater
** When i2 equals 0,
     max(min(i1,18),1)
     if op2 is nonintegral1
     max(min(i1 * i1,18),1)
     if op2 is an integral literal1.
When i2 does not equal 0,
     max(min(i1 * (9 * i2),18),1)
     if op2 is nonintegral1
     max(min(i1 * i1 * (9 * i2),18),1)
     if op2 is an integral literal1.
dmax if op2 is nonintegral or a
data-name;
d1 * op2 if op2 is an integral
literal

Notes:

  1. These results are subject to subsequent processing.

You must define the operands of any arithmetic statements with enough decimal places to give the desired accuracy in the final result.

Table 43 indicates the action of the compiler when handling intermediate results for fixed-point numbers.

Table 43. Determining When the Compiler Might Truncate Intermediate Results

Value of i + d2 Value of d Value of i + dmax Action Taken
< MAXLENGTH1
= MAXLENGTH
Any Value Any Value i integer and d decimal places are carried for ir.
> MAXLENGTH3 < dmax
= dmax
Any Value MAXLENGTH - d integer and d decimal places are carried for ir.
> dmax < MAXLENGTH
= MAXLENGTH
i integer and MAXLENGTH - i decimal places are carried for ir.
> MAXLENGTH MAXLENGTH - dmax integer and dmax decimal places are carried for ir.

Notes:

  1. MAXLENGTH has one of the following values:
    • 18 decimal digits

      +-------------------------------IBM Extension--------------------------------+

    • 30 decimal digits, when the (default) compiler option *NOEXTEND or the PROCESS statement option NOEXTEND is specified.
    • 31 decimal digits, when the arithmetic mode compiler option *EXTEND31 or PROCESS statement option EXTEND31 is specified.
    • 63 decimal digits, when the arithmetic mode compiler option *EXTEND63 or PROCESS statement option EXTEND63 is specified.

      +----------------------------End of IBM Extension----------------------------+

  2. If the value of i + d is an even number less than MAXLENGTH, the compiler converts it to an odd number by adding 1.

  3. If the value of i + d exceeds 63, system message MCH1202 can result, even if the statement includes the SIZE ERROR phrase.

If you think an intermediate result field might exceed MAXLENGTH digits, you can use floating-point operands (COMP-1 and COMP-2) to avoid truncation.

Related Information


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]