COBOL Manual for TNS and TNS/R Programs
Procedure Division
HP COBOL Manual for TNS and TNS/R Programsā522555-006
8-44
Common Features of Arithmetic Statements
Intermediate Data Items
For each arithmetic operation, an intermediate data item holds the result value until
that value is either used as an operand in another operation or assigned to a receiving
data item. The size of the intermediate data item depends on the operations and data
items used in the operation and varies from 16 bits (about four digits) to 128 bits (about
39 digits). If the algebraic size of the result exceeds the capacity of this intermediate
data item, a binary, floating-point, intermediate data item is used and the compiler
issues warning 85. Because floating-point arithmetic has a maximum precision of 16
digits and often is not exact, the result might be incorrect in the rightmost digit or digits.
Multiple Results
The ADD, COMPUTE, DIVIDE, MULTIPLY, and SUBTRACT statements can have
multiple results from performing arithmetic necessary to arrive at the final result to be
stored in the receiving item. During execution, multiple results are the same as the
results produced by a sequence of statements that either combine the value of an
intermediate data item with a single result or transfer the value to a receiving item.
These statements are in the same left-to-right order as that of the multiple results in the
actual statement.
For example, the results of the statement
ADD A B C TO C D (C) E
are equivalent to those of the statements
ADD A B C GIVING TEMP
ADD TEMP TO C
ADD TEMP TO D (C)
ADD TEMP TO E
TEMP is the intermediate data item. Any subscripts specified in a reference to a
receiving item are evaluated just prior to the assignment operation for that item.
Incompatible Data
Normally, whenever the contents of a data item are used in the Procedure Division and
the current contents of that data item are not compatible with the class and size
specified by its PICTURE clause, the result of the reference is undefined; that is, the
semantic rules of the COBOL language apply only when operands have values
corresponding to their descriptions. The single exception to this rule is the class
condition, which exists specifically to permit testing whether or not an operandās value
corresponds to its description. The presence of incompatible data can cause execution
of the run unit to terminate abnormally.
Some computations can generate a negative zero (for example, when the value of an
expression is -0.05, and this value is stored in a variable that is described as PICTURE
S99V9). When the program uses the value negative zero, it ignores the sign.