meggitt_62

Upload: bzkizosbb

Post on 04-Jun-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Meggitt_62

    1/17

    J. E. Meggitt

    P s eu d o D iv i s i o na n d P s e u d o M u l t i p l i c at i o n P r o c e s s e sAbstr act: Some digit-by-digit methods fo r th e evaluation of the elementary functions are describThe methods invo lve processes th at resemble repeated-addition mul tipl icati on and repeatesubtraction division. Consequently, th e methods are easy t o imp lemen t and the resultant executitimes a re short.

    IntroductionIt is customary n computers to build an arithmeticunit which is capable of add ing, subtracting, multiply-ing and possibly dividing. To perform more compli-cated operations it is usual to w rite routines tha t usethese basic operations, operating on words a t a time.However, in certain cases, digit-by-digit methods existfor the evaluation of certain functions. Some of theseare altractive because they can be mad e faster than thecorresponding subroutine methods, and also becausethey do not need so much storage space; sophisticatedfast subroutines or evaluating the elementary functionsrequire the storage of manyconstan ts. Hence, it isworthwhile considering whether more powerful arith-metic units could be providedwhich would be capableof performing these digit-by-digit methods.

    Th e advent of m icroprogramming as a method ofcomputer control has made it very easy to constructrelatively complicated arithm etic units . The methodsdescribed here are ideal for a machine with such con-trol. However, thesemethodsan also easily beimplemented in a conventional manner.Th e first part of this pape r will show flow diagramsof four routines.Thes e will form , respectively, ylx,log[1 + ylx)], an- ylx), and d* for given y and x.A striking eature of these four routines is theirsimilarity. This means tha t a comm on microprogramsubroutine or common hardwaremay be used, in oneof four different modes of operation,and this, ofcourse, represents an economy in he numb erof micro-instructions or in the amo unt of hardware required.These ideas are particularly helpful to the designer ofsmall but powerful machines, but they may also haveapplications for larger machines, where it is requiredto have the elementary functions built in.Th e second par t of this paper shows how essentially,by reversing the abo ve routines, tan y, xey and xy2may be generated.210 In the apert will, be upposed tha t base 10 arith-

    metic is being used. This is by no means a restrictioHowever, the fact that operations can be performewith base 10 is anadvantage in thearea of smmachines where itmay be nconvenient to provdecimal-to-binary conversion.Section 1: Division

    Th e basic repeated s ubtraction process is, of courvery well known ndeed. F or completeness the fldiagram for it is shown in Fig. 1 .Initially register A contains an n digit word y , aregister B an n digit word x. x s subtracted from ymany times as is possible until A becomes as small ascan without going negative. The num ber of subtrations is recorded n a counter whose contentsartransferred to a shifting register Q . One oomanysubtraction s is performed and this requires a subsquent addition. It is possible of course to omit haddition and alternatelysubtract and add, and thpossibility remains in the cases of the routines to described. How ever, for he sake of simplicity, thcomplication w ill be omitted. ( A )are nowmultiplied 10 and the process is repeated. When it has been peated n times as shown by the counter j , he ( Q ) athe n digits of the quotient ylx.To keep the digits of the answer less than 10, theis a restriction y/x < 10. A must be a register of lengn + 1 to allow for he shift eft. Th e answer is,course, exact, except for the remainder.

    Modijied divisionTh e modification to this basic routine which is prposed here is to provide a modifier register M. Thisloaded uring ach ubtraction cycle immediateprior to subtraction. After each subtraction the pdivisor which is in B is updated.This s done adding to the divisor, the contents of the modifiershifted j places to the r ight, where th e j + l t h uotie

    IBM J O U R N A L A P R I L 1962

  • 8/13/2019 Meggitt_62

    2/17

    ENTERIET i = 0ADD 1 TO C O U N TA ) + (B ) - (A )

    SHIFT a)NE PLACELEFTCOUNT TO LEAST SIGNIFICANT

    HIFT (A ) ONE PLACELEFTIDD 1 TOTEST

    Figure 1 Flow diagram orelementary divider.Initially A contains y and B contains x . The quo-tient is obtained in Q.

    digit q j , is being formed. A flow diagram for thisprocess is shown in Fig. 2.It will transpire roughly that the various routinesdiffer only n that the contents of different registersareused to load the modifier. It will be found indeed thatin one case the digits q j are such thatlog[l + ( y / x ) ] = q j log(1+ 1O-j) ;iin another thattan(y/x) = q j tan IOiwhile in a thirdJylx = c qjl0.

    iThe precise ways in which the various routines workwill next be described. Flow diagrams for all of themare shown together in Fig. 3.To f o rm log[l + (y /x )I

    The method used is essentially Briggs method modified

    so that the main part of the calculation is by a pseudodivisionprocess, and handled in uch a way thataccuracy is retained.The method consists of choosing digits qj so thaty + x = x 1 + O ) Q ,j = Owhere y and x are given t digit positive numbers. Thecalculation of qj is made to resemble a division. Whenthis has been done,log[l + ( y / x ) ] = q j log(1 + 10-j) . (2)

    jThe calculation is split into two parts. In the firstpart, digits q j are calculated. In the second, thelogarithm is calculated from (2) using stored valuesfor log(1 + 10-j). This latter calculatiog turns out to

    be a pseudo multiplication.

    Figure 2 Flow diagram or elementary modifieddivider.Initially A contains y an dB containsx . Thepseu-do quotient is obtained in Q.ENTER

    SET i = 0-

    SET (M)

    ( A ) - ( B ) - ( A )+O/ / \O h

    I SHIFT (a )ONE PLACEEFTADD 1 TO C O U N T C O U N T TO LEAST SIGNIFICANTI I HIFT (A ) ONE PLACELEFT I

    DD 1 TO

    21 1

    IBM JOURNAL APRIL 1962

  • 8/13/2019 Meggitt_62

    3/17

  • 8/13/2019 Meggitt_62

    4/17

    Part I of calculationThe basic idea is to suppose that

    (I + 10-~)4~1j - 1[ k = 0has been calculated, where qo q j - are digits thathave already been chosen, and hat they have beenchosen in such a way as to make this expression assmall as possible. It is now required to find the nextdigit qj . For this, successive calculations ofy p = y (1+ 10-k)qk (1 + 10-j>. 1) (3)j - 11 k = Ofor a = 0, 1, 2 * q j are made. qj is defined byY41(j)2 0 > Y , , l (i).

    The idea is to try the effectof including furtherfactors (1 + lO-j), with the object of keeping y, )positive but making it small.It is convenient to define

    The successive y's and x's may be calculated from(3) and (4) by the recurrence relationsy u + l j )= yu( i ) o-jx j )xu+l j) x , ( i )+ lo-jxu(j)By design the y's get smaller and smaller. To keepaccuracy, it is convenient to do what is done in thecase of a true division and putz u ( j ) = loiy j ) . ( 6 )

    Then for each j the recurrence relations become

    1 ( 5 )

    and these are the equations for the evaluation of q j .qj is defined byzql(j) = 0 > zql+ 1). 8 )This is clearly a pseudo division process. z:j) is thepseudo remainder and x,(j) is the pseudo divisor. Itonly differs from a true division in that the pseudodivisor is being constantly updated by the addition ofIO-jx, ) to it instead of being held constant.When qj has been found it is clear that the initialconditions for the evaluation of q j + arez o j + l )= loj ly j + l )= lo'+' i )= lozx o i + l )= i )Hence, when q j has been found, the process continuesfor the extraction of qj+l with the pseudo remainderzql(i)multiplied by 10. This exactly esembles whathappens in the case of a true division.

    0 Y 4 l 41 (9)' '?J

    When the process is first started it is also clear thatz0(O) = yx0(O)= x . (10)

    Hence, the following algorithm is established:If y is divided by x using a long division repeatedsubtraction process wherein the divisor x is continuallyupdated by having 10-jx added to it during the for-mation of thequotient digit, q j , then he pseudoquotient qo, q l , qz is such thatlog[l + ( y / x ) ] = q j log(1 + 10 ). (11)j = O

    The flow chart in Fig. 3 contains this process andshows it explicitly. It is identical for this case, withthat shown in Fig. 1 for a true division except for theprovision of the modifier register Mas shown in Fig. 2,whose contents update the divisor. Each time a sub-traction is performed the modifier is set with thedivisor itself, so that the recurrence relations (7) aresatisfied.Magnitudes of x and y

    It is desirable that all the quotient digits qj should beless than 10. As in the case of a rue division, thisimplies an upper restriction on y/x. Indeed, forqo < 10, we must havey / x < 21 1 .For subsequent digits the condition is automaticallymet because it is certainly met for a true division, andin the pseudo division the divisor is being continuallyincreased. When y/x is small, the calculationapproaches a true division and not surprisingly10gCl Y / X >l Y l X

    Register lengthsx and y are each n digit numbers with, it is supposed,their decimal points aligned. However, since the num-ber contained in B grows during he calculation, Bmay have to be a register of length greater than n. Thecontents of B at the end of the calculation are, in fact,x (I + 1 0 - ~ ) 4 k

    k = O= y + x by construction,

    so that it is obvious that a register of length n + 1 forB will suffice. The remainder register A , will also neverhave to contain a number greater than ten times thatin B . Hence, the length of register A is made n + 2.Q is given a length of n, and the pseudo quotient iscalculated to n digits. Considerations of accuracyshow that it is not worthwhile calculating more digits.Table 1shows a typical calculation, with the successivecontents of registers shown explicitly. 213

    IBM JOURNAL APRIL 1962

  • 8/13/2019 Meggitt_62

    5/17

    AccuracyApproximations only occur when the shifted modifieris added to t he divisor. However, it is easy to see theeffect of the figures dro pped in this shift. It will besupposed thathe ropped figures are used forrounding n he addition. The first round-off erro rsoccur when q1 is being calculated. Let 6xk be the

    Table I Example of formation of log[l + ( y l x ) ] .y = 67719 and x = 21608.

    rounding error introduced at the k i h ounding. Thewhen q1 has been formed , (A) will be in error by6y, = 41- 1)6x, + ( 4 1 - 2)6x2 + . . (1while ( B )will be in error by6x1 + 6x2 + . * + axq1 (1

    Before q2 is formed,(A) are shifted left. Hence, ifconsider only errors tha t are caused while q1 is beiformed, there will be an errorof6 y , = lO[(q, 1)6x, + 41 - 2)6x, + ]+ q2(8x1 + . + ax,,)

    j B A Count Q in A when q2 has been found and so on.in A of21608771921608 2 1608 1

    When 4- has been formed, there will be an err

    43216 461 1143216 4321686432 2895

    1 8643289502 86432 289500864 86432

    200002

    6y,-, = 1O -2[(ql 1)6x, + (41 - 2)6x, + . 1+ (10 -~q, + 1 0 - ~ q ,+ + q n - l )x (6x1 + 6x2 + . + JX,,). (1

    In the worst case q1 = q2 = q3 = * = 96 x l = 6 x 2 = * . = 6 .

    00020 It is thenoundhat6 y , - , = 45 x 10 -26.8729603068 18737296

    88169 115772 28828169890517603

    3 89051 276030. 89 89051

    89140 18697989 8914089229 9783989 8922989318 8610_

    3

    .~

    Th e effect of round-off er rors that occur when q2formed is identical except that it is ten times as smaand so on. Thus, n he wors t case, the effect of rounding errors is to produce a total error in A, whq n - l has been formed,6y,-, = 45 x 10 -26(1 + 10 + + . )

    00203 = 50 X 10 -'6. (1When 4.- , as been formed,

    1 ( B ) - + x2

    qn- is found effectively by the true division of ( A ) b( B ) since, at this stage the effect of the modifier negligible. Clearly, the error in (A) predominates, andue to this cause there is an error in q n - l of3 50 x 10' 2[S/(y + x) ] . (1

    4 89318 861002033 Because of theoundingnhedditionnd becauit is supposed that at least one of y o r x contains20330 significant digits,[6 / (y + x ) ] < 5 x lo- . (1

    Zog,[l + ylx)] = 2 log, 2 + 3 log, 1.01 + 3 log,1.001 The worst case error in q n - l is, therefore, less thaA pseudo multiplication then causes the evaluation ofgiving log,[l + ( y l x ) ] = 1.4192. If moredigits of 2.5. Thu s, the last digit of the quot ient will never bthe pseudo quotientrealculatedalue for in error by more than 2.5. Due to the fact, howevelog , [ l + ( y l x ) ] = 1.419240 is obtained which is in fa ct tha t it is likely for round-off errors to com pensate,exact. is usual or q n - to be exact in typicalcalculations214 (Therobability of this happeningay,nact,e

    I B M JOURNAL A P R I L 1962

  • 8/13/2019 Meggitt_62

    6/17

    ENTER

    SET j = n - 1

    1 -TEST FUNCTI ON

    L O GT -

    SET ( 8 ) = IOi L O G 1 + 10-1 SET ( 8 ) = IOi TAN I0-1

    1SHIFT (Q) ON E PLACE RIGHT

    LEAST SI GN I F I C A N T TO C OU N T

    ,( A ) + (B) - (A) SHIFT ( A ) ON E PLACE RIGHTd 1

    1SUB. 1 FROM j

    TEST

    j > O i < OEX I T

    Figure 4 Flow d i a g r a m o r m u l t i p l i e r .Initially multiplier is in Q, and B contains multiplicand. The product is obtained in A . This routine is used forI ) multiplication, 2 ) Part 2 of log11+ (y lx )] calculation and 3 ) Part 2 of tan- (ylx) calculation.calculated.)Therefore, themethod s inherently anaccurate one.

    Part 2 of calculationThe second part of the calculation consists of findinglog[l + ( y / x ) ] from (11). The base to which thelogarithm is calculated is determined by the base towhich the stored constantslog(1+ 10-j) arecalculated.It should be observed that log,(l + 10-j) - 10-j.Thus, he decimal number qo q 1 q z q 3 is alreadya fairly close approximation to log,[l + ( y l x ) ] .Indeed, if working is carried to n figures, only aboutthe first half of th e qj cause corrections to be made .The formation of log[l + ( y / x ) ] from (1 1) clearlyresembles amultiplication. The numbe r in Q is the

    multiplier, while the multiplicand is given the valuelog(1 + 10-j) while multiplication by the digit qj istaking place. It is, therefore, onvenient to use apseudo multiplier for this operation. Th e op eration isidentical to an ordinary m ultiplier save that the multi-plicand is set from some read-only storeo the equiredvalue, as each digit of the multiplier is processed.Figure 4 hows the process explicitly and also showshow it is combined with a true multiplication. It isgood enough, of course, to set10' log(1 + lo-j) = 1 (19)while the least significant half of the multiplier digitsare processed. This economizes on thenumber ofstoredonstantsequired. 215

    IBM JOURNAL APRIL 1962

  • 8/13/2019 Meggitt_62

    7/17

    The intention is that this routine should beno moretha n a particular mode of the multiplication routine.I t is, of course, true that thepseudo multiplication anddivision could be combined nto single process.They have, however, been split so that they m ay becombined with true multiplication and division.Execution times

    The time to form log[l+ (y/x)] using this meth od willbe about three multiply times, and, of course, this in-cludes the division of y by x which conventionallywould have to be done before the calculation of thelogarithm . This assertion may be slightly unfair sinceit assumes that multiplication would be performed bya repeated addition process, without he use of anytricks for speeding it up. However, the pseudo pro-cesses described are also performed without any tricksand it may be that similar tricks are applicable in allcases.Log z

    If it is wished to evaluate log z, where z is an n digitnumber with the decimal point to the left, then thecomplem ent of z should be pu t in A and z itself intoB before the process is begun.Then y = 1 z so tha tlog[l + (y/x)l = log[l + (1 - z)/z] (20)= og zy / x will not be too large if z is no t too small. Thismakes an excellent method of finding log z if 0.1 5 z< 1, and so this method can be used for finding thelogarithm of the fract iona l part of a floating pointnumber.

    To form tan (y/x)The methodused is one thatresembles Brigg's m ethod,but it is applied t o complex logarithms. T he centralidea is to find integers q j such that( X + iy) ( 1 10-j)Q = R , (21)where x and y are n digit positive numbers and Ris real. When this is done

    j = O

    lOg(x + i ~ log R q j log(1 10-j) . (22)j = O

    The imaginary part of this equation givestan-'(y/x) = q j tan- ' 1 0 - j . (23)

    Calculation is again split into two pa rts. In the first,integers qj are calculated by a pseudo division process.In the second tan-l(y/x) is found by a pseudo multi-plication, using stored values for tan-' 10-j.Part I of calculation

    The idea is to suppose that ( x + i y ) (1- lO-k)qk

    j = O

    j - 1216 k = O

    has been calculated, where qo qj- are digits thave already been chosen in such a w ay as to ma kthe imaginary par t of this expression as mall spossible, and to consider what is required t o findF or this, successive calculations ofx a j ) + iy, ' = ( x + iy) T (1- 1 0 - k ) y l - lo-jyj - 1

    k = O (aremade or a = 0 1 , 2 qj. qj is defined by

    That is, y j) must be made as small as possible, whkeeping it positive.

    By design, the y's get smaller a s the process is cotinued. Hence, to keep accuracy, it is convenient write

    The recurrence relations then become

    These are obeyed repeatedly untilz q y2 0 > z q j + j ) . (2

    This is again a pseudo division process with z$) tpseudo remainder and xa(j) the seudo divisor. In thcase, however, the pseudo divisor is repeatedly udated by adding to t lO- jz/). As in the case logarithms, it is clear that when the iteration for qis started, initial conditions are

    so that the pseudo remainder has to be shifted oplace to the left. Also, at the beginning of the entiprocess

    Hence, t he following algorithm is established. Ifis divided by x using a ong division repeatedsubtraction process wherein the divisor is continually udated by having lO-'jz added to it (z the remaindeduring the formationof the quotient digit q j , then tpseudo quotient qoql is such thattan- l (y /x) = q j an -' 10 . (3

    The flow chart in Fig. 3 shows th e process expliciand t only differs from hat or he ormation j = O

    I BM JOURNAL A P R I L 1962

  • 8/13/2019 Meggitt_62

    8/17

    stead of to (B).Magnitudes of x and y

    Since 0 5 tan-l(y/x) 5 4 2 t is obvious qo 5 2.Also, since the divisor is continually being increased,it is clear that all the other pseudo quotient digits areless than 10. Hence, all thequotient digits are lessthan 10 and there are no restrictions on the ratio y lx .

    J A

    Table 2 Example of fo rmat ion of an- (y/x).y = 30912 and x = 59438.i B A Count Q0 59438 30912

    ~~ ~

    1 5943809120 000003091 5943862529 2496822497 6252965026 1871531872 6502666898 1221271221 66898681195229

    2 68119 55229055 681 1968174 48417148 68 17468222 41599742 6822268264 34777535 6826468299 27951128 6829968327 21 1212

    21 6832768348 14288514 6834868362 745377 6836268369 6175

    3 68369175000484 68369175000480 68369

    549131

    At this stage it becomes a straight division processgiving68369179 9 04809

    A pseudo multiplication then causes the evaluation oftan- ' (ylx) = 4 tan-' 0.1 + 8 tan 0.01 + 9 tan0.0001 giving tan (ylx) = 0.4796. Zfm ore digits of thepseudo quotient are calculated ta n- ( y l x ) = 0.479578.The exact answer is 0.479574.

    Register lengthsx and y are each n digit numbers with their decimalpoints aligned. At the endof the process, B will containapproximately the number R from (21), andR = [ X + iyl 11- lO 1Q (32)

    j = O

    00004 from which it may be shownR 5 21x + iy]_I 2J j max(x, y ) . (33)Hence, a registerof length n + 1 will certainly ac-commodate R. Therefore, as for theogarithm routine,it is sufficient o make B a register of length n + 1andA a register of length n + 2.Table 2 shows a typical calculation set out in detail.

    AccuracyThe discussion of accuracy is virtually the same as thediscussion for logarithms, since, again the only errorstha t occur, occur when the contents of the modifierare shifted and added to update he divisor. Errorsoccur because of the figures dropped. The previousdiscussion applies to all pseudo division processes ofthis type.The result, therefore, is that the worst possible errorin the last digit of the quotient q,,l-l is50 x 10' 26/R . (34)

    In this case too, therefore, the worst possible erroris of 2.5 in the last digit of the pseudo quotient, and,of course, owing to the cancellation of errors, t isusual for qn- to be exact. 217

    1BM JOURNAL APRIL 1962

  • 8/13/2019 Meggitt_62

    9/17

    9 Part 2 of calculationTan (y/x) is now calculated from 3 1 ) . This is doneby means of a pseudo multiplication and is exactly asdescribed for he logarithm and is shown in Fig. 4.However, the multiplicand is set to 10 tan 10 forsuccessive values o f j nstead of to 10' log(1 + 10-j).For 213 of the values of j it is accurate enough to set1Ojtan 10 = (35 )and this, therefore, saves stored constants.

    Execution timesThe ime to form an (y/x) using thismethod isabout three multiply times and, of course, thisonealso gains a division.To form tan-' z , it is a very simple matter to puty = 10 zx = 10for a suitable scale factor lo , though then, of course,the extra division facility is wasted.AssessmentThewooutineshat have been described giveaccurate values of log[l + (y/x)] and tan (y/x) inthree multiply times which is quicker than any of thecurrent subroutine methods. They have the advantageof simplicity since they merely employ pseudo dividersand pseudo multipliers. Moreover, they are notundulyexpensive with stored constants.9 Square roots J y TIt is also tempting to use the modified divider that hasbeen described for the extraction of square roots. Thiscan be done at theexpense of slightly more complica-tion. The method is the standard digit by digit one.The flow diagram is shown also in Fig. 3 . It is seenthat the only difference from the previous routines isthat the modifier is set to a constant, while the pseudodivisor is altered between the extraction of successivedigits.Integers qj are found such that

    2y = x q,10L = O

    so tliat(37)

    Jylx = jlo-'j = O

    Here, it isupposed that qo qj- have beenfound and t is required to find q j . This is done bycalculating successively(39)

    for a = 0, 1,2 * .The object again is to make yo ) as218 small as possible but o keep it positive. Define

    IBM JOURNAL APRIL 1962

    This can be calculated from the recurrence relation

    As before, for accuracy's sake, it s convenient to puza j )= lOjy, ) and so get the recurrence relations

    (43These equations are iterated untilS(j)goes negativeThat is, q j is defined by

    zq j ( j )= 0 > z q j + ( j ) . (44These equations are again like those that arise in adivision process. z,( j) s the remainder, and x,(j) is the

    pseudo divisor, which is continually being updated bythe addition of the constant 2x, shifted j places.The initial conditions for the extraction of q j + arehowever, more complicated. Clearlyz o ( j + ) = l o zq j ( j ) .Howeverx o ( j + 1 ) = ( j ) - x l o - x l o - j - 1 .xq.t (45

    Thus, before thecalculation of q j + l the pseudodivisor must e pdated by subtracting from i0.9 x IO- jx , and this constitutes the extra complicaAt the beginning of the process(46

    x0(O) = x .Hence, the following algorithm sobtained. If apseudo division of y by x is performed, where themodifier is held constant at 2x, and if between thecalculation of successive digits 0.9 x 10 x is subtracted from he divisor, then the quotient is JTx.Of course the numbers 2x and 0 . 9 ~an be calculatedbefore the process is begun.This routine probably looks more familiar if it isperformed with x = 1. It should be observed that iis very easy to set the modifier at 2x inabinarymachine and lso that in a binary machinehe factor 0.9

    that occurs in the subtractions replaced by a factor 0.19 Magnitudes of numbersIt is convenient to suppose that y and x are given asnumbers with n significant digits and that either theirdecimal points are aligned or else misaligned by onedigit. If they are aligned this implies that 10 > y/x >1/10, If they are misaligned, y is shifted one place leftto align them before calculation is begun. In the latter

  • 8/13/2019 Meggitt_62

    10/17

    digits will be less than 10.Sizes of registers

    At the end of the process B will contain approximately2 JXy. (47)x 5 C, the largest n digit number y 5 IOC.Hence,2 4 5 5 2 4 1 0 c . (48)

    Hence, as before, a register of length n + 1willsuffice for B and a register of n + 2 for A . A typicalcalculation is shown in Tab le 3.Accuracy

    Errorsoccur when the shifted modifier updates thedivisor and figures are drop ped, and also, when th edivisor is updated between the extraction of successive

    A Count y

    Table3 Exampleofform ation of square root iy = 77208, X = 16804,2x= 33608,0.9x = 15124.i B A Count Q0 168047208 00000336086804

    50412 6040433608 5041284020992 15124-

    1 3361 68896722571512-

    2 336 707457 108 1 239495336 7108171417 168414336 7141771753 96997336 7175372089 25244151

    00002

    0002 1

    31938 25244034 719387197280502 13419727200608530 2342006720406524 15-

    002 14

    42025 3 36524072025 02143

    7202837203 1

    3

    2932 15 17202822187

    7203172034372037372040

    149156720347712272037

    508521435

    The answer is therefore 2.1435.f the process is continued it gives 2.143507, whichhappens to be exact . Not e that it is assumed y and xhave their decimal points aligned.

    digits. Th e first errors are hose hat have been en-countered previously. The others are of the same typebut occur in the worst case one ten th a s o ften. Hence,from (16) there is a worst case error of about55 x 10 -26 (49)in A when qn- has been formed.qn- was obtained essentially by a division of ( A ) by(B) . B contains at this time 2&. Hence, the worstcase error inqn-- 55 x 10n-2/2)(6/Jxy). (50)

    Since, by design x and y each contain, at least, nsignificant digitsGIJXy < 5 x lo- . ( 5 0

    This eads to aworst case error n qn- of 1.5 and 219

    IBM JOURNAL APRIL 1962

  • 8/13/2019 Meggitt_62

    11/17

    so this routine has the same kind of accuracy as theothers.Conclusion

    It is, therefore, possible to makea simple pseudodivider and a simple pseudo multiplier w hich betweenthem, operating in different modes, can compute ylx,log[l + (Y/X)l, tan-'(y/x), Jylx.Section 2: Mult ip l icat ionThe processes that have been described in Section 1may be reversed. This reversal leads t o m ethods forformingexponentials, angents and squares. In hereverse processes, multiplications become divisionsand divisions multiplications. In themultiplicationstha t result, it is naturally expected that the least sig-nificant digit of the multiplier will be processed firstand that the answer will be obtained as the ratio ofthe contents of registers A and B . This implies that anultimate extra division is necessary.It transpires, however, that accuratemethods orforming exponentials and squares can be devised thatavoid this final division, but in the multiplications hatthey contain, the order of multiplication is changedand the most significant digit of the multiplier is pro-cessed first. In the case of the tangent, how ever, themethod must be the exact reverse of the method forthe inverse tangent. This makes the methods slightlydifferent from each other.

    To form exponentialsThe method to be described enables x(ep 1) to becalculated fo r given positive p and x. p is expressed asp = qjlOg(1 + lo-]), (52)j = Ofor integers qj. Then, clearlyx(eP 1) = x n (1 + 1 O- j ) q j - 53)[ = O

    If p were negative, it would be possible to make anexpansion of p in terms of log(1 IO-j). This wouldbe the reverse process of what would be don e n findinglog[l y / x ) ] or positive x and y . This was not treatedexplicitly in the first section of the paper, but the eadershould observe that the only difference for that caseis tha t he pseudo divisor shouldbeupdated by asubtraction rather than by an addition.In floatingointpplications, it is probablysufficient, however, for p to be positive and so onlythis case will be dealt with now.Th e calculation is split into two parts. In the first,integers qj are found by a pseudo division, and in thesecond the exponential is evaluated by a pseudomultiplication.

    Part 1T o find integers q j a division of p is made. The ivisor220 isset to log(1 + 10-Jj rom a ead only store while the

    IBM JOURNAL APRIL 1962

    digit qj is being formed . Figure 5 shows the proceexplicitly, and it is clearly t he reverse of wh at is showin Fig. 4. Of course, constants Ojlog(1 + 10-j) artaken from the same store.Magnitude of p

    It is necessary to have all digits q j less than 10. Thmeans that p < 10 log 2 for qo < 10, while this condition is met automatically for other digits sincelog(1 + 10-j) < 10 log(1 4 o-j-1) . (5p and the constants 10' log(1 + 10-j) must have thedecimal points aligned. The constants are stored asdigit numbers, the decimal point being to theeft. Hencthe number p must be shifted if necessary before tprocess is begun. n pseudo quotient digits are calclated.The accuracy to which p is known will nwa rrant the calculation of furthe r digits.

    Part 2To calculate

    j = O (5apseudomultiplication is performed using qo qnas the pseudo multiplier, and starting with the mossignificant digit qo.Fo r this, suppose that

    has already been calculated and that it is now requireto introduce a further factor (1 + 10-j)q~.Definey, = x (1 + 1 0 - k ) y l + 10-jy - 1j - t

    [ k = O(57xa( i )=

    Then, for successive a s, the recurrence relations

    x a + l ( j ) = x a i ) l o - j x a ( j )are obtained and these ar e iterated for a = 0 * qjIt is convenient to m akeza ( i )= lojy i )Then the recurrence relations become

    a (59

    These quations now resemble a multiplicationz i j ) is the partial sum, while x / ) is the multiplicandwhich is being continually updated by the addition oitself shifted j places. qo * 4. is the multiplier.When qj has been processed, initial conditions fothe processing of qj+ are

  • 8/13/2019 Meggitt_62

    12/17

    zo ( i+ ) = loz i)x o ( i + l ) = i)

    41 Hence, a pseudo multiplications being made, where(61) x is the pseudo multiplicand that is repeatedly updated,There is, therefore,a shift left of the partialproduct identical with that for a true multiplication (multi-he flow chart n Fig. 6 shows this process. It isbetween the processing of successive digits and this is plication f rom the left) except for the provision of theexactly what happens in the case of a true multiplica-tion where the most significant digit is processed first. plicand after each successive addition.odifier register which updates the pseudomulti-

    If it is required to calculate x e prather thanx(eP ),

    XqJ and qo .q n - is the multiplier.

    When the process is startedthen the partial sum register A should initially be set(62) at x.Of course, x may be set at one for the calculationof e p but use of the method's full power is attractive.

    Figure 5 Flow diagram or divider.A contains dividend and B co ntains divisor. The quotient appears in Q. This routine is used for 1 ) division, 2 ) Part Iof x ( e p - ) calculation and 3 ) Part 1 of tan x calculation.

    ENTER

    SET j = 0

    TEST FUNCTI ON

    EXPv

    SET B ) = IOi L O G 1 + 10-j)

    v( A ) - (B)-(A)

    l

    A D D 1 T OO U N T

    SHIFT (Q) O N E PLACE LEFT

    @HIFT (A ) O NE PLACE LEFT4A D D 1 TO j1TEST i

    j < n j > nEXIT 221

    I BM JOURNAL APRIL 1962

  • 8/13/2019 Meggitt_62

    13/17

    ENTER1ET = n - 1 0 )

    ISHIFT ( Q ) ONE PLACE RIGHT (LEFT)

    LEAST (MOST) SIGNIFICAN T TO COUNT

    TEST FUNCTION

    I SUBTRACT 1 F R O M C O U N T II

    I I

    (PRECOMWTED CONSTA NT)

    HIFT (A ) ONE PLACE RIGHT (LEFT)

    TEST FUNCTION

    I EXITcFigure

    OT SQUARE

    UBTRACT (ADD) 1 F R OM ( T O ) j

    6 Flow diagram or modified mul tip lier.B contains pseudo multiplicand, Q contains pseudo multiplier, and A contains pseudo product. This routine is usefor I ) multiplication, 2) Par t2of x (ep ) calculation, 3) Part 2 of tan p calculation and 4 ) xq 2 calculation. Wherchoice is indicated, multiply and tangent routines employ the first possibility, while exp and square routines emplothe second.Register sizes that register B does not overflow. Inn applicatiowhere loatingpointarithmetic is used, it is likelAs the calculation progresses, the size of thepseudo that x will beanumber with n significant digits anmultiplic and increases. Eventually it will ap proxi- hat 1 5 e p < 10. In this case B shouldbe registe222 mately equal xep, and so caremust be takeno see of length n + 1.

    IBM JOURNAL APRIL 1962

  • 8/13/2019 Meggitt_62

    14/17

    Table 4 Example formation of x ep 1).x = 21608 and p = 1.4192. A n initial pseudodivision of p gives Q ) = 20330. This pseudodivision expresses p as p = 2 loge 2 + 3 loge1.01 + 3 log, 1.001.

    j B A Count Q

    0 2 16082 1608432164321686432

    1 864322 86432864

    872968738816988289051

    3 890518989 14089892298989318

    00000216082 16084321664824

    6482406482400864326568832872966656128881696744297

    674429708905 16753202189140676211618922967710390

    2

    1

    003

    2

    1

    03

    2

    1

    0

    03300

    3 300030000

    00000

    The method, therefore, gives the answer 67710. Thecorrect answer is 677154. The decimal point is alignedwith that in the number x. There appears to be a largeerror. How ever, this disappears i f ( Q ) are calculated to6figures rather than 5 and the process is continued onestage further. f p is known, however, only to the numberoffigures shown, this further accuracy is spurious.

    At the end of the process, A will contain a numberof similar size, except tha t it has been shifted left n - 1times. Hence, A must be a register of length 2n. It isunfortunate hat A has to be such a long register.However, itcanbe oined up with register Q as is

    often done, since the number of digits in Q decreasesas the number in A increases.Accuracy

    The number that is in A at the end of the process isthe required answer an d it is necessary to find howmany digits of it are accurate. Inaccuracies occur inthe pseudo m ultiplication process, due to the drop pingof figures when the pseudo multiplicand is updated.The way in which these affect the contents of A isexactly the same way in which the contents of A wereaffected in the corresponding pseudo division process.Hence, from (16), theerror in ( A ) when q n - l hasbeen processed is at worst50 x lO' '6. (63)

    Because of the rounding in themodification, 6 = 0.5.Thus, there s an error of about 2.5 in then l th igitfrom the right in A . ( A ) are, therefore , shifted n - 1places to the right. A now contains a numberof lengthn + 1 with its decimal point aligned with that in thenumber x . Its least significant digit is in error by a tmost 3.Inaccuracies also occur because in the preliminarydivision only n digits of the pseudoquotienthavebeen calculated. However, as has been explained, thisisonly the accuracy tha t is warrante dand his n-accuracy is inherent in the number system used.The met hod, herefore, is inherently an accu rate ne.Table 4 shows a typical calculation with the successivecontents of registers shown.

    Execution timesx e p or alternatively x(eP- 1) is formed in approxi-mately three multiply times, so this is certainly a fastmethod.

    To for m angentsThe method to be described enables tan p to be cal-culated. The answer is obtained as a ratio and as hasbeen explained, a final division is necessary.It is supposed that 0 4 5 7~12. is expressed asp = qjtan 10 (64)for integers q j . An evaluation ofx + i y = R (1 + ilO-j)q' (65)is then made for some real R.Clearly thentan p = y / x . (66)

    The integers qj are obtained by means of a pseudodivision, and x and y are then calculated by means ofa pseudo multiplication.Part I

    The pseudo division is shown in Fig. 5. It is identicalwith the corresponding process used in forming he

    j = O

    j = O

    223

    I BM J O U R N A L APRIL 1962

  • 8/13/2019 Meggitt_62

    15/17

    expon ential, excep t con stant s 10' tan 10 are usedinstead of 10' log(1 + 10-j).Magnitudes of p

    Since p 5 4 2 , qo 5 2; therefore sincetan 10 < 10 tan lo-j-' (67)all oth er digits q j are less than ten.As in the case of the exponen tial, p and the constants10' tan 10-j must have the ir decimal points aligned.The number p is, therefore, shifted ifnecessary. npseudo q uotient digits are calculated.

    Par t 2To calculateR n (1 + ilO-j)Qj = oa pseudo mu ltiplication is performed using qo * qn-as the pseudo m ultiplier, and starting with the leastsignificant digit qn- 1. Define

    n - 1x , j ) iy, ) = R (1 + ilO-k)qk(l+ i l0-3 (69)k = + 1andut zo(j)= 1Ojy;j). (70)

    Then or successive values of a, he recurrencerelations

    are obtained , and these are iterated for a = 0 qj .Again these equations resemble a multiplication.z,() is the partial product. x , j ) is the pseudo multi-plicand which s continually being updated by thesubtraction of z,(i) shifted 2 j places. qo * q n - l isthe multiplier.After qj has been processed, q j - is processed andthe initial conditions are

    At the beginning of the process(73)

    Thus,a pseudo multiplication of R by qo * q n -is made, starting with th e least significant digit, q n - l .This is exactly like a tru e multiplaction except for th eupdating by subtraction, of the multiplicand.The f low char t for this process is shown in F ig. 6also.

    digit number, and register B is made of length n + 1A never has to contain number more han entimes that in B, so A is made of length n + 2. A nexample is shown in Table 5.Accuracy

    The contents of A and B at the end of the process arin error dueo the dropping of figures when he shiftecontents of M update the pseudo multiplicand.The effect of this cause is easily seen . Th e final ratioof ( B ) to (A) will be tan(p + 6,) for some small ainstead of tan p. It is convenient to discuss errors interms of 6,. If themethod or orming an inverstangent is applied to ( B )and ( A ) , it will be found thastep by step heircontentsapproxim ate their conTable 5 Example of formatio n of tan p . p = 0.4796An initialpseudo division gives Q) 04809.Thpseudo division expresses p a s p = 4 tan-10.1 +tan- 0.01 + 9 t a r 10.0001. ( B ) are initially se

    for convenience at 1 O O O O O.i B A Count Q4 100000 00000 9 00480__ -

    1OOOOO 900000 03 100000 90000 0 000482 100000 9000 8 000041 100000

    99999 109000 711 999999998808999 62199889996708987 531 999679993608954 44199369989508890 3

    51 998959984408785 261 99844

    Register sizesThe pseudo m ultiplicand decreases ashe process con- 71 99783tinues. Initially, it contains R, which is arbitrary. F or

    9918308629 1

    224 accuracy's sake, it is set to the largest convenient n + 1 9971208412 0

    IBM JOURNAL APRIL 1962

  • 8/13/2019 Meggitt_62

    16/17

    j B A Count Q1 99712 80841 4 00000

    808 997 129890480553 3

    180689049709879457 2279570989430376555 1376643039053770858 0

    0 905377085 0 00000A division of (A ) b y (B) leads oa value of tanp = 0.5201. The correct answer is 0.52010.Values of sin p = 0.4614 and cos p = 0.8872 canalsobe obtain ed. The correct values are 0.4614 2 and0.88725.

    tents during the forma tion of the angent. Actually,after digits qo * * qj have been formed in the inversetangent process, the conten ts of B and A will exceedthe corresponding contents in the tangent rocess by afactor n:=o1 + 10-2k)qk. However, rounding errorsoccur similarly in both processes. If compensatingerrorsoccur n he inverse process at exactly thoseplaces where errors occurred in the forw ard process,then tan tan(p + 6,) will be calcu lated as p , therebeing an error 6,. From the discussion of errors forthe inverse tangent process it is, therefore, clear tha t 6,is at worst 2.5 in the least significant figure of p , andso this gives a measure of the error n he angentprocess. In short, he dropping of figures when themodification is performed gives the same errors in thetangent as in he inverse tangent process.

    Trigonometrical functionsThis method produces two numbers, x and y whoseratio is tan p . To obtain tan a furtherdivision must beperformed and obviously care has to be taken to seethat x is not too small.

    It is also possible to form sin p and cos p f romsin p = J y 2 / ( x 2 + y 2 )cos p = J x 2 / ( x 2 + y') . (74)

    These may be calculated by first squaring x and yand hen using thesqua re oot process previouslydescribed. In a microprogram m achine in particular,the necessary control for this is easy to provide.If the sines and cosines are held in n digit stores withthe decimal p oint one place from the left-hand end,

    errors due to the trigonometrical p art of the methodwill never exceed 2.5 in the least ignificant digit place.Execution times

    x and y are obtained in three multiply times. Tan pmay be calculated in four times, while sin p and cos pwill take ap proximately seven multiply times.Tofo rm squares

    Th e square root method may also be reversed, to givea method for finding squares. This, of course, is notof much value but is mentioned here for interest'ssake. It enables x q 2 to be calculated fo r given x and q.Apseudomultiplication is performed. x is theinitial pseudo multiplicand and q is the multiplier andmultiplication is performed tarting with themostsignificant digit of q. At each stage, the pseudo multi-plicand is update d n exactly the way thepseudodivisor was updated in the square roo t process. Th epseudo product is then x q 2 . The proof of this followsalmost exactly the p roof for the square root method.Register sizes

    It is convenient to suppose that x and q are numberswith n significant digits. It may then be shown th atregister B has to have length n + 2 t o allow for thegrowth of the pseudo multiplicand. Register A has tohave ength 2n + 1 to allow for he succession ofn 1 shifts left.Accuracy

    The way in which errorsoccur is exactly the wayerrors occur in the square root routine. Hence, thereis an error in ( A ) at worst of 55 x 10' 26 when qn -lhas been processed. Accordingly, at he end of theprocess thecontents of A are shifted right n 1places, giving an error of not more than 3 in the leastsignificant digit of ( A ) , ( A ) being now a number withn, n + 1 or n + 2 significant digits.

    Decimal pointsIf it is assumed that the n digit numbers x and q havetheir decimal point one place from the left-hand end,that is 1 5 x , q < 10, then the decimal point of x q 2is aligned with them; that is 1 2 x q 2 < 1000.This routine is also shown in Fig. 6, and a workedexaniple is included in Table 6.

    AssessmentThis method enables x q 2 to be formed in twomultiplytimes. It seems itmay have some value incertainapplications.

    ConclusionThe second section has shown how x ( e P ) , tan p ,sin p , cos p ,x q 2 may be calculated using pseudomultipliers and dividers.All the elementaryunctionsay,herefore, be 225

    I B M JOURNAL APRIL 1962

  • 8/13/2019 Meggitt_62

    17/17

    Table 6 Example of formation of x . x = 1.6804, 2x = 3 .36 08 , 0 . 9 ~ 1 .51 24, q = 2.1435.j B A Count Q j B A Count Q

    1

    2

    0 168043360850412336088402015124-688963361722571512-7074533671081336714173367175333672089151

    0000016804168045041267216

    67216068896741056

    741056070745748 1305710817552386714177623803717537695556

    2

    1

    0

    1

    0

    43

    2

    1

    0

    14350 31938 34719723472006347204015

    435002025 37202837203 1372034372037372040

    35000 -

    76955560719387702749871972770994707200677171476

    77171476072025771786785720287718588137203177193084472034772002878720377720749 15

    50000

    OOOOO

    The answer given is herefore 7.7207. Thecorrecanswer is 7.72075.

    generated using the methods described. In a machinewith microprogram or conventional ontrol, it islikely :th at ne general pseudo multiplier/dividerroutine would be constructed. This would have manybranches in it, and the particular flow pat h requiredwould be set up by the function decoder. This wouldenable multiplication, division and the calculation ofthe elementary functions to be performed very eco-nomically in terms of the number of microinstructionsor of the conventional hardware required.The methods described are as fast oraster than anyconventional subroutine methods. These methods are

    extremely attractive for small machines where this not,perhaps, space to provideconventional suroutines.

    References1 . A. Ralston nd H. S. Wilf, Mathematical MethodsDigital Computers, John Wiley and Sons, Inc., 1960.2. J. H Wensley, A Class of Non-Analytical Iterative Pcesses, TheComputerJournal, 1, No. 4, 163 Jan.1959Received August 29 ,1961

    226