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

DIVIDE Statement
Because division is a rather complicated mathematical operation, and because the computer is
performing scaled integer arithmetic instead of floating-point arithmetic, the rules stating the precision
of HP COBOL division are somewhat complicated.
Effect of GIVING
When the GIVING phrase is present, a single quotient is computed. The appropriate number
of fraction digits in that quotient is determined from the receiving operand having the greatest
number of fraction digits.
When no GIVING phrase is present, a separate quotient is computed for each receiving data
item. Such a DIVIDE statement with multiple receiving data items is exactly equivalent to a
sequence of DIVIDE statements, each having a single receiving data item and all having the
same divisor. The appropriate number of fraction digits in each quotient is determined from
the corresponding receiving data item.
Effect of Decimal Point Placement
Under the mathematical rules for division, fraction digits in the divisor cause the significant
digit positions of the quotient to appear shifted to the left with respect to the significant digit
positions of the dividend. This corresponds to moving the decimal point of the dividend to the
right the same number of positions as would be necessary to make the divisor an integer:
1.00/0.3 = 10.0/03 = 03.3
Put another way, each divisor fraction digit cancels a trailing digit position in the dividend,
which then reappears as a leading digit position in the quotient. This causes a problem when
the actual dividend has fewer fraction digits than the sum of the number of digits in the divisor’s
fraction and the number of digits in the appropriate quotient’s fraction.
Suppose you want to divide two data items described as:
DIVIDEND PICTURE 9(10)v9(5) USAGE DISPLAY
DIVISOR PICTURE 9(4)v9(7) USAGE DISPLAY
If the computer aligns them by scaling each up by 7 decimal places, it has to extend the
dividend’s fraction with 2 additional digit positions filled with zeros. It would be dividing a
17-digit integer by an 11-digit integer.
Because the sum of the number of actual dividend digits and the number of appended zero
digits cannot exceed 36, there are very few combinations of operands in a DIVIDE statement
for which it is impossible to append enough zeros.
Size Error
All digits in the value assigned to the receiving data item are accurate unless either the size
error condition occurs for that data item or at least one trailing digit is fictitious (that is, set to
0 because it was not generated by the division operation).
Arithmetic Expressions
HP COBOL maintains intermediate results during the evaluation of arithmetic expressions. Arithmetic
expressions occur only in the COMPUTE statement, the EVALUATE statement, the relation condition,
the sign condition, the reference modifier, the parameters of the ENTER statement, and function
arguments.
NOTE: The precision of COBOL arithmetic computation has limitations. The COMPUTE statement
is particularly sensitive. Use of an appropriate sequence of the ADD, SUBTRACT, MULTIPLY, and
DIVIDE statements permits you to attain the precision you desire, provided that the PICTURE clauses
describing the operands do not imply potential values of exaggerated significance. There is no
guarantee that the result of an arithmetic expression will be the same in different implementations.
Arithmetic Operations 263