magnitude comparison and overflow detection in modular arithmetic computers

9
SIAM :REVIEW Vol. 5, No. 4, October, 1963 MAGNITUDE COMPARISON AND OVERFLOW DETECTION IN MODULAR ARITHMETIC COMPUTERS GEORGE E. LINDAMOOD AND GEORGE SHAPIRO 1. INTRODUCTION The use of modular arithmetic in digital computers was first suggested in 1955 by Valach and Svoboda [4]. At that time, they pointed out that using modular arithmeticmthat is, representing an integer by its residues with respect to several mutually prime modulinwould permit additions and multiplications to be executed in a highly parallel fashion, thus eliminating altogether the genera- tion of carries and allowing "one machine-cycle" multiplication. They also recognized that several disadvantages inherent in the modular arithmetic systemnin particular, difficulties in performing operations in which all residues a,re required simultaneouslywould have to be overcome before modular arith- metic computers would be feasible, much less practical. Since 1955, several investigators, including Aiken and Semon [1], Garner [2], and Svoboda [3], have devised solutions to most of these problems to the extent that modular arithmetic computers are now feasible. It still remains to delineate those applica,ions in which such computers would be better suited than "conventional" computers. In this paper, it is our purpose to develop new modular arithmetic methods for performing fundamental operations essential to all but the simplest digital computers" the operations of magnitude comparison and overflow detection. Our approach will be concerned with the theoretical solutions to these problems and not with the actual implementation of these operations, but in order to raise no new difficulties in the latter area, we will use only "basic" modular arithmetic operations such as addition, subtraction, multiplication, and com- parison of residues. First, we will show how to compare two numbers algebraically through the use of "two-sided" mixed radix notation, and how to convert a number from the usual "residue" notation to the "two-sided" mixed radix form by a succession of subtractions and multiplications. Next, we will take up the problem of de- tecting overflow in modular arithmetic addition, and give a simple necessary and sufficient condition for such overflow. Finally, we will consider the more difficult problem of detecting multiplicative overflow and present two methods of solution. The first is an iterative method involving only additions, subtractions, and magnitude comparisons; the second is a much simpler and faster method, but it requires a stored table of powers of two. This work was supported by the Electronic Technology Laboratory, Aeronautical Systems Division, Wright-Patterson Air Force Base, Ohio, under Contract Number AF 33(657)7899. Received by the editors December 7, 1962 and in revised form May 6, 1963. Air Arm Division, Westinghouse Electric Corporation, Baltimore, Maryland; and the University of Maryland. Air Arm Division, Westinghouse Electric Corporation, Baltimore, Maryland. 342 Downloaded 11/21/14 to 129.120.242.61. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Upload: george

Post on 28-Mar-2017

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Magnitude Comparison and Overflow Detection in Modular Arithmetic Computers

SIAM :REVIEWVol. 5, No. 4, October, 1963

MAGNITUDE COMPARISON AND OVERFLOW DETECTIONIN MODULAR ARITHMETIC COMPUTERS

GEORGE E. LINDAMOOD AND GEORGE SHAPIRO

1. INTRODUCTION

The use of modular arithmetic in digital computers was first suggested in1955 by Valach and Svoboda [4]. At that time, they pointed out that usingmodular arithmeticmthat is, representing an integer by its residues with respectto several mutually prime modulinwould permit additions and multiplicationsto be executed in a highly parallel fashion, thus eliminating altogether the genera-tion of carries and allowing "one machine-cycle" multiplication. They alsorecognized that several disadvantages inherent in the modular arithmeticsystemnin particular, difficulties in performing operations in which all residuesa,re required simultaneouslywould have to be overcome before modular arith-metic computers would be feasible, much less practical. Since 1955, severalinvestigators, including Aiken and Semon [1], Garner [2], and Svoboda [3], havedevised solutions to most of these problems to the extent that modular arithmeticcomputers are now feasible. It still remains to delineate those applica,ions inwhich such computers would be better suited than "conventional" computers.

In this paper, it is our purpose to develop new modular arithmetic methodsfor performing fundamental operations essential to all but the simplest digitalcomputers" the operations of magnitude comparison and overflow detection.Our approach will be concerned with the theoretical solutions to these problemsand not with the actual implementation of these operations, but in order toraise no new difficulties in the latter area, we will use only "basic" modulararithmetic operations such as addition, subtraction, multiplication, and com-parison of residues.

First, we will show how to compare two numbers algebraically through theuse of "two-sided" mixed radix notation, and how to convert a number from theusual "residue" notation to the "two-sided" mixed radix form by a successionof subtractions and multiplications. Next, we will take up the problem of de-tecting overflow in modular arithmetic addition, and give a simple necessaryand sufficient condition for such overflow. Finally, we will consider the moredifficult problem of detecting multiplicative overflow and present two methodsof solution. The first is an iterative method involving only additions, subtractions,and magnitude comparisons; the second is a much simpler and faster method,but it requires a stored table of powers of two.

This work was supported by the Electronic Technology Laboratory, AeronauticalSystems Division, Wright-Patterson Air Force Base, Ohio, under Contract Number AF33(657)7899. Received by the editors December 7, 1962 and in revised form May 6, 1963.

Air Arm Division, Westinghouse Electric Corporation, Baltimore, Maryland; and theUniversity of Maryland.

Air Arm Division, Westinghouse Electric Corporation, Baltimore, Maryland.

342Dow

nloa

ded

11/2

1/14

to 1

29.1

20.2

42.6

1. R

edis

trib

utio

n su

bjec

t to

SIA

M li

cens

e or

cop

yrig

ht; s

ee h

ttp://

ww

w.s

iam

.org

/jour

nals

/ojs

a.ph

p

Page 2: Magnitude Comparison and Overflow Detection in Modular Arithmetic Computers

MAGNITUDE COMPARISON AND OVERFLOW DETECTION IN COMPUTERS 343

2. MAGNITUDE COMPARISON

To illustrate the difficulties involved in comparing two numbers in modulararithmetic, let us use the moduli 7, 5, 3, and 2 and consider the modular arith-metic representations for 59, 78 and 103"

59 - (3, 4, 2, 1); 78 - (1, 3, 0, 0);

103 - (5, 3, 1, 1).

As these three examples indicate, the modular arithmetic residues give nodirect indications of the relative magnitudes of the numbers to which theycorrespond. All of the residues for 78 are less than or equal to the correspondingresidues for 103, but on the other hand, the same is true of the residues for 78and 59.The problem, then, is to devise some method for using the residues to compare

the magnitudes of two numbers in modular arithmetic; the solution is found ina simple generalization of fixed radix notation. In decimal notation, for instance,we determine the larger of two numbers by successively comparing the cor-responding digits, which are really coefficients of powers of 10"

103 1.10 0.101 -- 3" 10 is greater than 78 0.10 -t- 7.10 8.10

because

1>0.

The same principle of positional notation holds if we use any radix r > 1. Thatis,

(1) x anr an_lrn-1 -- -- alr ao,

where 0 -< a < r, is greater than

y bnr bn_lr- br bo,

where 0 <= b < r, if an > bn. And, if an bn, then x > y if an_ > bn_, andso forth. The important relation which gives positional notation this propertyis that, for any integer j >__ 0,

(2) r’+1 > ajr + ai_r’- air ao,

provided that 0 =< a < r.If we now allow r to vary in the successive terms of (1) above, we have mixed

radix notation in which x is represented by the coefficients, a, in the expression,

(3) x an rn- rn_2 ro -- an-lrn-2rn-3 ro -{" -" alro + ao,

where rn, r_, r0 are the radices. As before, we require that 0 =< a < r.It follows that x is greater than

(4) y bnrn-lrn-2 ro " bn-rn-2rn-3 ro -- -- bro + bo,

Dow

nloa

ded

11/2

1/14

to 1

29.1

20.2

42.6

1. R

edis

trib

utio

n su

bjec

t to

SIA

M li

cens

e or

cop

yrig

ht; s

ee h

ttp://

ww

w.s

iam

.org

/jour

nals

/ojs

a.ph

p

Page 3: Magnitude Comparison and Overflow Detection in Modular Arithmetic Computers

344 LIND_A_MOOD AND SHAPIRO

where 0 <= bi < ri if am > b, provided that the radices, r are in the same orderin both (3) and (4).

Furthermore, if the radices, r, are pairwise relatively prime, we can convertan integer from "residue" form to mixed radix notation by the following method.From (3) above, it follows that

x-- x0- a0 (modr0)and

(5) x--- (x_ a_)/r_ ai (mod ri),

for 0 i -< n. Since the radices are relatively prime, r0, r, r_ can beeliminated successively from those equations to obtain the coefficients, a0,

a, a. Moreover, since 0 -< a r, these operations can be performed in a"purely modular" fashion and the resulting coefficients stored as a set of "resi-dues". Indeed, insofar as the computer is concerned, the coefficients, a, are

iust another set of residues; only the programmer can distinguish them from"genuine" residues by how he uses them.For exumple, if x 59- (3, 4, 2, 1) and ra 7, r: 5, r 3, r0 2, the

elimination process produces the following array"

rood 7 5 3 2

x0 3 4 2 1 a0

Xl 1 4 2 ax2 2 4 a2

x 1 a.

The second row is calculated from

x= (xo-ao)/ro= (3- 1)/2 1 (modT),

(4- 1)/2-- 4 (rood5),

(2-- 1)/2------ 2 (mod3).

Similarly, the third row is

x (Xl al)/rl (1 2)/3-- 2 (mod7),

(4- 2)/3 4 (mod5)and the last row is

x3 (x.- a2)/r2 (2- 4)/5--= 1 (modT).

Since we defined x in (5) such that x a (mod ri), we have the result"

x a3r2rlro - a2rlro "4- aro + a0 1 (5.3.2) -f- 4 (3.2) -t- 2 (2) A- 1 59.

Now we can compare magnitude in modular arithmetic exactly as in decimal---.namely, by comparing the coefficients, a and b, of two numbers, respectively,in the order i n, n 1, 0. Furthermore, if the "inverses" of the r--

Dow

nloa

ded

11/2

1/14

to 1

29.1

20.2

42.6

1. R

edis

trib

utio

n su

bjec

t to

SIA

M li

cens

e or

cop

yrig

ht; s

ee h

ttp://

ww

w.s

iam

.org

/jour

nals

/ojs

a.ph

p

Page 4: Magnitude Comparison and Overflow Detection in Modular Arithmetic Computers

MAGNITUDE COMPARISON AND OVERFLOW DETECTION IN COMPUTERS 345

that is, integers si. such that sijr 1 (mod rj), i < j--are stored in a table,any division by an r in the elimination process above can be performed as amultiplication by the corresponding set of si.’s. Thus, the entire eliminationprocess for the (n d- 1) moduli, r, rn_l, r0, can be completed using onlyn subtractions and n multiplications (in modular arithmetic). The conversionfrom mixed radix notation back to "residue" form is done simply by evaluatingthe expression (3).

Professor Harold S. Shapiro of New York University suggested that we ex-tend mixed radix notation by allowing the coefficients, ai, to take on both posi-tive and negative values--in particular, let al =< (r 1)/2 for odd moduliand Jail -< r/2 for the even modulus. (We say the even modulus because themoduli still must be relatively prime.) For the even modulus, we must furtherrequire that only one of the values, a r/2 or ai -r/2, be permitted, sinceeach a.i may take on exactly r distinct (consecutive integer) values. With theserestrictions on the coefficients, a, we call the expression (3) "two-sided" mixedradix notation. An important property of this notation is"THEOREM" Let rn, rn_, to, be any (fixed) positive integers such that ro

is even and the other r are odd. Let a, an_ a0, be (variable) integers suchthat (-r0/2- 1) <- ao <- ro/2and la <- (ri- 1)/2 forO < i <= n. Definexbythe equation (3) above and M by M rnrn_ to. Then, (-M/2 - 1) <= xM/2. (Note that if we had made the condition on a0 to be-ro/2 <-_ ao <-(r0/2 1), then the conclusion of this theorem would be that -M/2 <= x <=(i/2- 1).)

Proof" For x >__ 0, substituting the conditions of the theorem into (3) gives

x =< [(rn 1)rn_rn_2-..r0 d- (rn_ 1)rn_2rn_3...ro-- -- (rl 1)ro + r0]/2.

Combining and cancelling terms on the right side reduces it to (rrn_l ro)/2M/2, which is the desired result. Similarly for x -<_ 0,

x >= --[ (rn 1)rn_lrn_2...ro - (rn-1 1)rn_r_3...ro-- - (r-- 1)r0-- (r0-- 2)]/2(rr_ ro 2)/2 --M/2 -- 1.

If ai and r are defined as in the theorem, it follows from the proof that, forany integer j => 0,

which is the "two-sided" mixed radix equivalent of (2). If y is defined by (4),then x > y if an > b, etc. It also follows that x > 0 or x < 0 according as

a.+( 0) is positive or negative, where aj+ a+s 0. Therefore, themagnitude comparison procedure can also be used to determine the sign of anumber in modular arithmetic. However, it is very important to rememberthat the theorem and these consequences are valid in general only if the evenmodulus is ro.

Dow

nloa

ded

11/2

1/14

to 1

29.1

20.2

42.6

1. R

edis

trib

utio

n su

bjec

t to

SIA

M li

cens

e or

cop

yrig

ht; s

ee h

ttp://

ww

w.s

iam

.org

/jour

nals

/ojs

a.ph

p

Page 5: Magnitude Comparison and Overflow Detection in Modular Arithmetic Computers

346 LINDAMOOD AND SHAPIRO

Conversion from "residue" to "two-sided" mixed radix form is performedexactly as above except that provision must be made for negative coefficients.This is accomplished most readily by using least absolute value residues, whichare subject to the same restrictions as the coefficients, ai, in the above theorem.For example, if we permit only the residues 0 and 1 (rood 2), the moduli

r3 7, r. 5, rl 3, r0 2, will allow unique representation of all integers xsuch that -104 _-< x -<_ 105. Then 103 ,- (-2, --2, 1, 1) produces the followingarray as r0, rl and r2 are eliminated"

rood

X0

Xl

X2

X3

7 5 3 2

-2 -2 1 1_ a02 1 0 al3 2 a2

Hence, 103 3(5.3.2) -t- 2(3.2) + 0(2) + 1. Similarly, (3, 1, -1, 1) -59 2(5:3-2) + 0(3.2) 1(2) + 1, and (1,-2, 0, 0) - 78 3(5.3.2)-2(3.2.)+ 0(2) -t- 0.

If we use [a, 32, hi, a0] to denote the "two-sided" mixed radix coefficientsof x, it is now obvious that [2, 0, -1, 1] < [3, -2, 0, 0] < [3, 2, 0, 1], or 59 <78 103.

3. OVERFLOW DETECTION IN ADDITION

As in the previous section, we begin our discussion with examples. The fol-lowing illustrate modular arithmetic addition with and without overflow. "Two-sided" residues and the moduli, 7, 5, 3, and 2 are used.

78-- (--59) -(1, --2,0,0) @ (--3, 1,1,1) (--2, --1, 1, 1) -19;

103-t-78- (--2, --2,1,1) @ (1,--2,0,0) (--1, 1,1,1) -29.

In the first addition the sum is correct, but in the second, it is not, because over-flow has occurred--that is, 103 -t- 78 181 > 105, so that the sum is givenmodulo 210.The problem to be considered here is how to detect additive overflow when it

occurs, by means of modular arithmetic operations on the addends and sum.Two properties of such overflow are immediately obvious: First, at most one"place" of overflow can occur, since 0 =< a < K and 0 _-< b < K imply that0 =< al + ]bl < 2K, where K is the machine range;second, overflow cannotoccur if a and b have opposite signs, because in that case, 0 _-< [a[lal- Ibl]-<- ax (la[, ]b[) < K.For the remaining cases we have the following THEOREM: If a and b have

the same sign and c =- a + b (mod K), then overflow occurs--that is,b >= K--if and only if c < [a (or c < ]b I).Proof: If no overflow occurs, thenc-- a-t-b] a[ + ]b[ _-> a]. Hence,

c < a implies that overflow has occurred.

Dow

nloa

ded

11/2

1/14

to 1

29.1

20.2

42.6

1. R

edis

trib

utio

n su

bjec

t to

SIA

M li

cens

e or

cop

yrig

ht; s

ee h

ttp://

ww

w.s

iam

.org

/jour

nals

/ojs

a.ph

p

Page 6: Magnitude Comparison and Overflow Detection in Modular Arithmetic Computers

MAGNITUDE COMPARISON AND OVERFLOW DETECTION IN COMPUTERS 347

Conversely, if (one "place" of) overflow occurs, then c a[ + blg < la],since Ibl- K < 0.

If the "two-sided" residue notation is used, both a and bl are at mostM/2, where M is the product of the moduli. Therefore, al + b --< M, so thatoverflow (I a + [bl > M/2, in this case) can be detected by the presence ofthe "wrong" sign on c a -k b (mod M).

4. OVERFLOW DETECTION IN MULTIPLICATION--METHOD I

The problem of overflow detection in multiplication is considerably moredifficult than in addition because more than one "place" of overflow can occurin a modular arithmetic multiplication--that is, x.y may be greater than 2K.Consider the following examples in which "two-sided" residues are used withthe moduli, 7, 5, 3, and 2"

78.103 (1, -2,0,0) (3 (-2,

9.29 (2, --1, 0, 1) (/) (1, --1,

--2,1,1)

(-- 2, 1, 0, 0) - 54 8034 (mod 210)

-1,1)

(2, 1, 0, 1) - 51 --- 261 (mod 210).

If z x.y (mod M) is zero, then overflow occurs if and only if both x and yare non-zero (rood M). And, as in addition, if z has the "wrong" sign or if0 # zl < Ix[ (or 0 # z] < Yl), then overflow has occurred. But ifz >= x and [z = Y [, overflow may occur, as in the multiplication of 9

by 29 above, or may not occur, since z] Ix.y] _>_ [xlif x].ly[ < Kand

In the case where [z >= Ix and ]z >_- Y I, we proceed to detect overflowas follows. Let k be a positive integer such that ]c =<_ K < (/c -- 1)2, and assumefor convenience that Ix >- Y [. Define a and b by a Ix ]c and b [y[

/. Obviously, if a -< 0 and b -<_ 0, then Ix I" ]Yl -<- k, and overflow does notoccur. Likewise, if a > 0 and b > 0, then Ix I" Y[ >= (/ -t- 1) , and overflowdoes occur. (Here, and in the remainder of this section, we may say that overflowoccurs if and only if x l" Y > K. If "two-sided" residues are used, the machinerange is different for positive and negative integers. This complicates matterssomewhat, but with a few modifications, the following method is still valid.)

In the case where a > 0 and b _-< 0, let us examine the expression, x ]. Y(k + a). (l + b) k + (a + b)l -t- ab. If we define d = 0 such thatd K k2, then Ix [.I Y overflows if and only if (a q-- b)k + ab > d. Ifwe rearrange (a q-- b)k q-- ab to give a (b -k lc) -k bk a y + bk, and notefrom the definition of b that 0 =< -b [b[ < lc and [y[ =< /, it follows thata =< [b implies that a Y[ -< [b].]yl -<- [b[/c. Therefore, if a =< [b [, then(a -k b k + ab a ly]/ bk <= 0 <- d, and overflow does not occur.Let us consider the remaining case--that for which a > b and a > 0 => b.

It follows from the definition of b that

(a--k b)lc + ab + b (a-k b).(lc - b) (a q- b).[y].

Dow

nloa

ded

11/2

1/14

to 1

29.1

20.2

42.6

1. R

edis

trib

utio

n su

bjec

t to

SIA

M li

cens

e or

cop

yrig

ht; s

ee h

ttp://

ww

w.s

iam

.org

/jour

nals

/ojs

a.ph

p

Page 7: Magnitude Comparison and Overflow Detection in Modular Arithmetic Computers

348 LINDAMOOD AND SHAPIRO

Therefore, if (a nu b).[yl > d - b, overflow occurs. But, ]b < /c, so thatd b < d -t- / K. Hence, if (a - b). Yl overflows, it is certainly greaterthan d - b; otherwise, we can compare (a -{- b). y with d -t- b to determineconclusively whether or not Ix I" Y I--or equivalently, x. y--overflows.Now only one problem remains" that of determining whether or not

(a -t- b). [Yl overflows. For that purpose, we set x (a nu b) and repeat theentire procedure for x.y. It may be necessary to do this several times, thusmaking this an iterative method for overflow detection.

Let us summarize by defining x0 x, x x- -}- b k, a x /,and z =- xi.y (rood M). Then, if any x.y (a_ -}- b).y overflows, x.y over-flows ;that is, if for any i, either z 0 while x 0 Y or 0 z < x I,then x.y overflows. Otherwise, if a0 _-< b [, no overflow occurs; and if anya _-< b I, for i > 0--since a+ _-< a 1, this must happen eventually--x.yoverflows if and only if (a0 + b). Yl x. [Yl > d -[- b.

Thus, we can detect multiplicative overflow with the above method, butseveral "iterations" may be required ia certain cases. Such instances probablyoccur quite seldom since the tests involving zl and xl are usually sufficientto detect any overflow in one or two "iterations."As an illustration of this method of overflow detection, let us reconsider the

second example of multiplication given above. We have K M/2 105, so weset/ 10 and d 5. Then, x0 29, y 9, z0 51 and z0[ > Ix0 [. Hence,it is necessary to calculate a0 Ix01 lc 19 and b [Yl ] -1. Sincea0-- 19 > b I-- 1, we setx--a0 nu b-- 18. Then, z-- -48--- 18.9 x.y,and since z has the "wrong" sign, overflow has occurred.

5. OVERFLOW DETECTION IN MULTIPLICATION--METHOD II

Since the overflow detection method given in the preceding section requiresso many operations, we have devised a simpler method which makes use of astored table. This method, unlike the preceding one, is valid only if "two-sided"residues are used or if integers between M/2 and M are regarded as being nega-tive-that is, any integer x such that M/2 < x < M rnrn_l ro representsthe negative integer, x M. Since provision would probably have to be madefor negative integers in a modular arithmetic computer anyhow, we feel thisslight loss of generality is not restrictive.As in method I, we first compare z x.y (mod M) with Ix and Y !. If

0 z >-- Ix (I x >= Yl), we refer to a table consisting of all integer pow-ers of two from 20 1 to 2n, where 2 M/2 < 2n+l, to find integers, pand q, such that 2- < Ix] _-< 2 and 2q-] < Y] ----< 2q. If p - q _--< n, then

xl’lYl -< 2+q --< 2n and no overflow occurs. Similarly, if n - 3 _-< p + q,then 2+’ -<_ 2+q- < Ix I. [Yl and overflow occurs.

If p - q n -[- 1, then 2- < Ix[. ]yl =< 2+ =< M, and any overflow willhave been detected by the presence of the "wrong" sign on z, or z 0 and

xl 0 Y I. Moreover, if p + q n + 2, then2 < Ix I.]yl --< 2+ -<- 2Mand any overflow such that M/2 < xl’]Yl <= M or 3M/2 < xl.lyl <- 2Mwill also have been detected by the same tests on z.

Dow

nloa

ded

11/2

1/14

to 1

29.1

20.2

42.6

1. R

edis

trib

utio

n su

bjec

t to

SIA

M li

cens

e or

cop

yrig

ht; s

ee h

ttp://

ww

w.s

iam

.org

/jour

nals

/ojs

a.ph

p

Page 8: Magnitude Comparison and Overflow Detection in Modular Arithmetic Computers

MAGNITUDE COMPARISON AND OVERFLOW DETECTION IN COMPUTERS

We must now differentiate between the two following cases for p + q n -t- 2"Case 1--2 < xl. Y] <= M/2, and overflow does not occur;Case 2--M < xl. Yl <- 3M/2, and overflow does occur. To do this, we

multiply 2p-1 by Yl and examine the sign of the result. In Case 1 we have2n--1 < IX/21 Yl 2P--l" Yl < IX I" Yl - M/2, so the sign of Zl 2p-l" Yl(mod M) will be plus; but in Case 2, we have M/2 < x/2 I. yl --< 2-1. yl=< 2-1. 2 2n+ <- M, so the sign of z will be minus.For example, the overflow in the multiplication of 9 by 29 in Section 4 above

is detected by Method II as follows"

x 29, y 9, andz 51, so [zl > Ixl > lYl.We refer to the table to findp 5andq 4. Then, p+q= 9 > 8 n+2,which indicates overflow.As a second example, consider the multiplication of x -31 and y 8 in the

same system. Then, x.y -248 -38 (rood 210), and [z > Ix > Y I.From the table we find p 5 and q 3. This gives p + q 8 n + 2, so we

2p-1calculate z "lYl 16.8 128 -82 (rood 210). Since the sign of zl

is minus, overflow has occurred.We can also give a different treatment to the above situation where n - 1 _-<

p -t- q <= n -t- 2. If we define a and b by a xl 2- and b Yl 2q-1,then

(6) x[’[y] 2+q-2 -t- a.2q-1 nu b.2p-1 nu ab.

Since 0 < a -<_ 2p- and 0 < b -< 2q-, then each of the four terms on the rightside of (6) is at most 2p+q-2 2n. Hence, multiplicative overflow occurs inx I" ylif and only if additive overflow occurs in (6).For example, overflow can be detected in the above multiplication of x -31

and y 8 as follows"From (6) we have

xl "Iyl 26-t- 15.22nu4.24-t- 15.4 64+ 60 + 64 + 60.

Overflow occurs in the addition of any two of these terms, so x ]. y overflows.In general, this treatment of the ease where n -t- 1 -< p -t- q <_- n -t- 2 requires

more operations than the treatment involving z -=- 2p-1. Y I, since two to sixmagnitude comparisons are required to detect the presence or absence of additiveoverflow in (6). Therefore, despite the appealing conceptual simplicity of thetreatment using (6), the other is preferable since it requires less machine opera-tions.

6. CONCLUSION

As we have seen above, magnitude comparison and overflow detection can beaccomplished in modular arithmetic using only "basic" machine operations.In the former case, a permanently stored table of "in.verses" of moduli---oneword of storage for each modulus--would permit conversion from "residue"notation to "two-sided" mixed radix form by n subtractions and n multiplica-

Dow

nloa

ded

11/2

1/14

to 1

29.1

20.2

42.6

1. R

edis

trib

utio

n su

bjec

t to

SIA

M li

cens

e or

cop

yrig

ht; s

ee h

ttp://

ww

w.s

iam

.org

/jour

nals

/ojs

a.ph

p

Page 9: Magnitude Comparison and Overflow Detection in Modular Arithmetic Computers

350 LINDAMOOD AND SHAPIRO

tions in a system with (n + 1) moduli. After conversion, sign detection reducesto a series of "bit" tests to determine the "highest order" non-zero mixed radixcoefficient and then to determine the sign of that coefficient. Similarly, magnitudecomparison is reduced to a series of comparisons between residues with respectto the same moduli.

Overflow detection, in the cases of addition and the first method given formultiplication, amounts to several additions, subtractions, and magnitudecomparisons, all of which are readily accomplished in modular arithmetic. Inthe case of the latter method for detecting multiplicative overflow, a "tablelook-up" technique is needed. Undoubtedly, the "arguments" would be ex-pressed in "two-sided" mixed radix form for such an operation, so the "look-up"procedure is really a series of magnitude comparisons. Moreover, the size of therequired table is quite modest even for modular arithmetic computers with alarge machine range. (For example, if M 10, n 29, which means that thetable would need only 29 words.) And as will be shown in future papers, the sametable can be used to greatly facilitate other very important arithmetic operationssuch as division and root extraction.Although the above magnitude comparison and overflow detection techniques

are more efficient than any others yet devised for modular arithmetic, they aresufficiently complicated so that they would best be used only as subroutines in arather carefully constructed computer program. Hence, it seems that modulararithmetic computers would not be well suited for "general purpose" computa-tion; but there may exist special applications where magnitude comparisons andoverflow tests are not often needed and where other requirements such as high-speed multiplication would make modular arithmetic computers very desirable.It is for these "limited purpose" applications that modular arithmetic com-puters seem destined.

REFERENCES

1. H. AIKEN, and W. SEMON, Advanced Digital Computer Logic, Wright Air DevelopmentCenter Technical Report, WADC TR-59-472, July, 1959.

2. H. L. GARNER, The Residue Number System, IRE Transactions on Electronic Com-puters, EC-8 (1959), 140-147.

3. A. SVOBODA, Rational Number Systems of Residual Classes, Stroje Nu ZprcovuniInformaci, Sbornik V (1957).

4. M. VALACH, and A. SVOBODA, Operatorove Obvody, Stroje Na Zpracovani Informaci,Sbornik III (1955), 247-295 (1956).

Dow

nloa

ded

11/2

1/14

to 1

29.1

20.2

42.6

1. R

edis

trib

utio

n su

bjec

t to

SIA

M li

cens

e or

cop

yrig

ht; s

ee h

ttp://

ww

w.s

iam

.org

/jour

nals

/ojs

a.ph

p