COBOL Manual for TNS/E Programs (H06.08+, J06.03+)

Table 52 shows some expressions that appear to be ambiguous and the COBOL interpretation of
them.
Table 52 Precedence in Arithmetic Expressions
InterpretationAmbiguous
(A / B) * CA / B * C
(A / B) / CA / B / C
(A ** B) ** CA ** B ** C
((A + (B / C)) + ((D ** E) * F)) - GA + B / C + D ** E * F - G
You can use arithmetic parentheses to:
Override the normal hierarchical sequence of execution in expressions whose evaluation must
not follow the normal precedence, for example:
A / ( B * C )
Clarify the hierarchical sequence of execution for the benefit of the reader, for example:
PRIN + ( INT * PERIOD )
It is recommended that division be the last operation performed in an expression, if possible;
otherwise, execution can be slow and precision can be lost.
Table 53 Operator-Operand Combinations
Successor Element
)(Unary Operator
+ or -
Binary Operator +
- * / **
VariableFirst Element
YesNoNoYesNoIdentifier or literal
NoYesYesNoYesBinary Operator
+ - * / **
NoYesNoNoYesUnary Operator
+ or -
NoYesYesNoYes(
YesNoNoYesNo)
An arithmetic expression must begin with an operand (which can be a parenthetical expression)
or a unary operator followed by an operand. Parentheses must always appear in balanced pairs
such that each left parenthesis precedes its corresponding right parenthesis within the expression.
Any operand can be preceded by a unary operator.
These rules apply to evaluation of the exponentiation operator in an arithmetic expression:
If the value of the base (left-hand) operand is 0, the power (right-hand) operand must have a
value greater than 0; otherwise, the size error condition exists.
If the evaluation yields both a positive and a negative real number, the value returned as the
result is the positive number.
If the result of the evaluation is not a real number or is not representable by the computer
system on which the operation is evaluated, the size error condition exists.
COBOL accepts noninteger as well as integer exponents.
Arithmetic Precision
The precision of ADD, SUBTRACT, MULTIPLY, and DIVIDE statements can be fairly easily stated.
The precision of arithmetic expressions is substantially more complex, because the compiler must
Arithmetic Operations 261