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.
Naive Division

Verify the division algorithm using = 52388 ; = 281


= 186 ; = 122
A = (52388)10 and B = (281)10 , i 4 3 2 1 0
ai 5 2 3 8 8
n = 3, m = 2
bi 2 8 1
= 52388 ≥ 281 × 10 : ∴ =1
← 52388 − 281 × 10 = 24288 ai 2 4 2 8 8

j = m – 1 = 1,
∗ = 2 × 10 + 4 /2 = 12 = 12, 9 = 9

← 24288 − 9 × 10 × 281 = −1002 =9−1=8


← −1002 +10 × 281 = 1808 ai 0 1 8 0 8
j = 0,
∗ = 1 × 10 + 8 /2 =9 = 9, 9 =9

← 1808 − 9 × 10 × 281 = −721 =9−1=8


← −721 +10 × 281 = −440 = 8 − 1 =7
← −440 +10 × 281 = −159 =7−1 =6

← −159 +10 × 281 = 122 Q = (186)10 and R = (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.
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