COBOL Manual for TNS and TNS/R Programs

Procedure Division
HP COBOL Manual for TNS and TNS/R Programs522555-006
8-50
Arithmetic Precision
MULTIPLY Statement
The number of fraction digits in the product is the sum of the number of fraction digits
in the two operands. The number of accurate nonfraction digits in the product is the
sum of the nonfraction digits in the two operands. The computational method used
verifies that an internal overflow never occurs for a MULTIPLY statement; therefore, all
digits in the value assigned to a receiving data item are accurate unless the size error
condition occurs for that data item.
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.