Intermediate results and arithmetic precision

The compiler handles arithmetic statements as a succession of operations performed according to operator precedence, and sets up intermediate fields to contain the results of those operations. The compiler uses algorithms to determine the number of integer and decimal places to reserve.

Intermediate results are possible in the following cases:

  • In an ADD or SUBTRACT statement that contains more than one operand immediately after the verb
  • In a COMPUTE statement that specifies a series of arithmetic operations or multiple result fields
  • In an arithmetic expression contained in a conditional statement or in a reference-modification specification
  • In an ADD, SUBTRACT, MULTIPLY, or DIVIDE statement that uses the GIVING option and multiple result fields
  • In a statement that uses an intrinsic function as an operand
  • Start of changeIn a statement that contains the ROUNDED phraseEnd of change

Example: calculation of intermediate results

The precision of intermediate results depends on whether you compile using the default option ARITH(COMPAT) (referred to as compatibility mode) or using ARITH(EXTEND) (referred to as extended mode).

In compatibility mode, evaluation of arithmetic operations is unchanged from that in releases of IBM® COBOL before COBOL for OS/390® & VM Version 2 Release 2:

  • A maximum of 30 digits is used for fixed-point intermediate results.
  • Floating-point intrinsic functions return long-precision (64-bit) floating-point results.
  • Expressions that contain floating-point operands, fractional exponents, or floating-point intrinsic functions are evaluated as if all operands that are not in floating point are converted to long-precision floating point and floating-point operations are used to evaluate the expression.
  • Floating-point literals and external floating-point data items are converted to long-precision floating point for processing.

In extended mode, evaluation of arithmetic operations has the following characteristics:

  • A maximum of 31 digits is used for fixed-point intermediate results.
  • Floating-point intrinsic functions return extended-precision (128-bit) floating-point results.
  • Expressions that contain floating-point operands, fractional exponents, or floating-point intrinsic functions are evaluated as if all operands that are not in floating point are converted to extended-precision floating point and floating-point operations are used to evaluate the expression.
  • Floating-point literals and external floating-point data items are converted to extended-precision floating point for processing.