COBOL Manual for TNS and TNS/R Programs

Procedure Division
HP COBOL Manual for TNS and TNS/R Programs522555-006
8-48
Arithmetic Precision
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 create intermediate data items as it evaluates the
expression. Arithmetic expressions occur only in the COMPUTE, ENTER, and
EVALUATE statements, the relation and sign conditions, function arguments, and in
reference modification.
In discussing precision, we ignore the presence of a scale factor or of any decimal
point; the arithmetic processing records and handles these elements separately. After
the computation is performed with integral values, the decimal point and scale factor (if
any) are then provided for the result.
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