COBOL Manual for TNS/E Programs (H06.03+)
Procedure Division
HP COBOL Manual for TNS/E Programs—520347-003
8-48
Arithmetic Expressions
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.
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.
Table 8-16. Operator-Operand Combinations
First Element
Successor Element
Variable
Binary Operator
+ - * / **
Unary Operator
+ or - ( )
Identifier or literal No Yes No No Yes
Binary Operator
+ -
* / **
Yes No Yes Yes No
Unary Operator
+ or -
Yes No No Yes No
( Yes No Yes Yes No
) No Yes No No Yes










