Integer Arithmetic - Division: Dr. Arunachalam V Associate Professor, SENSE
Integer Arithmetic - Division: Dr. Arunachalam V Associate Professor, SENSE
Integer Arithmetic - Division: Dr. Arunachalam V Associate Professor, SENSE
Dr. Arunachalam V
Associate Professor, SENSE
Introduction
• Dividend(D) is divided by the divisor (d) to get the quotient (Q) and the
reminder (R).
• = × +
• Division is the next operation to consider after multiplication.
• Optimizing division is almost as important as optimizing multiplication,
since division is usually more expensive, thus the speedup obtained on
division will be more significant.
• On the other hand, one usually performs more multiplications than
divisions.
• One strategy is to avoid divisions when possible, or replace them by
multiplications.
• An example is when the same divisor is used for several consecutive
operations; one can then precompute its inverse.
Types of division
• We distinguish several kinds of division:
• Full division computes both quotient and remainder,
• While in other cases only the quotient (for example, when dividing two
floating-point significands) or remainder (when multiplying two residues
modulo n) is needed.
• Exact division — when the remainder is known to be zero — and the
problem of dividing by a single word.
Normalized divisors
• In all division algorithms, we assume that divisors are normalized.
• We say that ≔ ∑ is normalized when its most significant word
satisfies ≥ ⁄2.
• This is a stricter condition (for β>2) than simply requiring that be
nonzero.
• If B is not normalized, we can compute A' = 2kA and B‘ = 2kB so that B' is
normalized, then divide A' by B‘ giving A‘ = Q'B‘ + R'.
• k is {0,1,2,3,….}
• The Q is Q' and R is R'/2k.
• If = 52388 ; = 281 B is not normalized.
• For k = 1 ; B‘ = 21 ×281 = 562 and now B is normalized.
• Also, A‘ = 21 ×52388 = 104776
• The Q is 186 and R is 244/21 = 122. [ 104776 = 186 × 562 + 244 ]
Naive Division
i 5 4 3 2 1 0 n = 3, m = 3
ai 766 970 544 842 443 844
bi 862 664 913
= 766 970 544 842 443 844 ≥ 862 644 913 000 000 000 ∶ ∴ =0
j = m – 1 = 2,
∗ = 766 × 1000 + 970 /862 = 889 = 889, 999 = 889
← 766 970 544 842 443 844 − 889 × 1000 × 862 664 913
← 766 970 544 842 443 844 −889 × 862 664 913 000 000 = 061 437 185 443 844
862 664 913 000 000 × 889
766 590 811
318 296 657 000 000
-766 909 107 657 000 000
766 970 544 842 443 844
061 437 185 443 844
i 4 3 2 1 0
ai 061 437 185 443 844
bi 862 664 913
j=1
∗ = 61 × 1000 + 437 /862 = 71 = 71, 999 =71