COBOL Manual for TNS/E Programs (H06.03+)
Procedure Division
HP COBOL Manual for TNS/E Programs—520347-003
8-53
Conditional Expressions
the division is performed before further evaluation of either of the preceding
statements. If the division operation is not the last operation in the expression and the
divisor is not 2, 4, 5, 8, or a power of 10, the division is carried out to 36 digits. As
many fractional digits as possible are kept. This number can be truncated depending
on subsequent operations. In some cases adjustment is not possible, so the compiler
uses binary floating-point arithmetic (and issues warning 85). Since the precision of
floating-point arithmetic is 16 digits and numbers cannot always be represented
exactly, the result might be slightly larger or smaller than the exact number. You might
have to use individual operations or revise the expression to guarantee accurate
results.
To obtain the maximum accuracy in an arithmetic expression that involves a division,
use parentheses or revise the expression as necessary to assure that the division is
the last operation performed. For example, you can rewrite the expression “a / b * c" as
"(a * c) / b".
When a conditional expression compares a variable and an expression, the number of
decimal places carried for the variable is used for the number of decimal places carried
for the expression.
When a conditional expression compares two expressions, the compiler determines
the smallest number of decimal places suitable for each of the expressions and then
uses the larger of those numbers of decimal places.
In a COMPUTE statement, the number of decimal places of the composite of operands
of the receiving fields is the number of decimal places of the expression.
If ROUNDED is specified on any operand, one additional decimal position is used in
the computation, then the rounding is applied to the result.
Conditional Expressions
Many different statements include conditional expressions. A conditional expression is
a syntactically correct combination of simple conditions, logical operators, and
parentheses that can be evaluated to a truth value. The truth value determines which
of two paths of control the object program takes.
The simplest form of a conditional expression is a simple condition. Complex
conditions are combinations of simple conditions and any of the logical operators NOT,
AND, and OR. COBOL allows you to abbreviate sequences of complex relation
conditions. You can use balanced sets of parentheses to control or clarify the order of
evaluation within a conditional expression.
Topics:
•
Simple Conditions
•
Complex Conditions
•
Abbreviated Combined Relation Conditions
•
Condition Evaluation Rules










