You are on page 1of 12

Integer Arithmetic - Division

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

Verify the division algorithm using = 52388 ; = 281


= 186 ; = 122
n = 3, m = 3 i 5 4 3 2 1 0
= 104776 ≥ 562 × 10 : ∴ =0 ai 1 0 4 7 7 6
j = m – 1 = 2, bi 5 6 2
∗ = 1 × 10 + 0 /5 = 2 = 2, 9 =2

← 104776 − 2 × 10 × 562 = −7624 =2−1 =1

← −7624 +10 × 562 = 48576 ai 0 4 8 5 7 6


j = 1,
∗ = 4 × 10 + 8 /5 = 9 = 9, 9 = 9

← 48576 − 9 × 10 × 562 = −2004 =9−1=8

← −2004 +10 × 562 = 3616 ai 0 0 3 6 1 6


j = 0,
∗ = 3 × 10 + 6 /5 = 7 = 7, 9 = 7

← 3616 − 7 × 562 = −318 =7−1 =6

← −318 +1 × 562 = 244


Q = (186)10 and R = 244/2 = (122)10 ,
Try this using BasecaseDivRem algorithm
• A = 766 970 544 842 443 844 and B = 862 664 913, with β = 1000, which
gives quotient Q = 889 071 217 and remainder R = 778 334 723.
• = = 862 ≥ 1000; and the B is normalized.
A = 766 970 544 842 443 844 and B = 862 664 913, with β = 1000, which
gives quotient Q = 889 071 217 and remainder R = 778 334 723.

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

← 61 437 185 443 844 − 71 × 1000 × 862 664 913


← 61 437 185 443 844 − 71 × 862 664 913 000 = 187 976 620 844

862 664 913 000 × 71


061 047 064
202 144 823 000
-061 249 208 823 000
061 437 185 443 844
187 976 620 844
i 3 2 1 0
ai 187 976 620 844
bi 862 664 913
j=0
∗ = 187 × 1000 + 976 /862 = 218 = 218, 999 =218

← 187 976 620 844 − 218 × 1000 × 862 664 913


← 187 976 620 844 − 218 × 862 664 913 = −084 330 190

862 664 913 × 218 = 218 − 1 = 217


187 144 199
← −084 330 190 + 1 × 862 664 913
916 752 034 = 778 334 723
-188 060 951 034
Q= = 889 071 217
187 976 620 844
-84 330 190 R =A= 778 334 723
Reference
1. Chapter 1.4.1 & 1.4.2 of Richard P Brent and Paul Zimmerman, “Modern
Computer Arithmetic”, Cambridge University Press 2010.
Next Class
SQUARE ROOT AND GCD

You might also like