Appendix C. 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
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 IBM
VisualAge® COBOL:
- 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 floating-point results. (For COBOL for Windows,
which runs with 80-bit extended-precision IEEE floating point, the accuracy
of extended-precision floating-point results is substantially reduced as
compared with the 128-bit extended-precision floating point that is used
with Enterprise COBOL for z/OS.)
- 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.
related concepts
Formats for numeric data
Fixed-point contrasted with floating-point arithmetic
related references
Fixed-point data and intermediate results
Floating-point data and intermediate results
Arithmetic expressions in nonarithmetic statements
ARITH
|