security/nss/lib/freebl/mpi/doc/div.txt

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/lib/freebl/mpi/doc/div.txt	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +Division
     1.5 +
     1.6 +This describes the division algorithm used by the MPI library.
     1.7 +
     1.8 +Input:    a, b; a > b
     1.9 +Compute:  Q, R; a = Qb + R
    1.10 +
    1.11 +The input numbers are normalized so that the high-order digit of b is
    1.12 +at least half the radix.  This guarantees that we have a reasonable
    1.13 +way to guess at the digits of the quotient (this method was taken from
    1.14 +Knuth, vol. 2, with adaptations).
    1.15 +
    1.16 +To normalize, test the high-order digit of b.  If it is less than half
    1.17 +the radix, multiply both a and b by d, where:
    1.18 +
    1.19 +             radix - 1
    1.20 +	d = -----------
    1.21 +              bmax + 1
    1.22 +
    1.23 +...where bmax is the high-order digit of b.  Otherwise, set d = 1.
    1.24 +
    1.25 +Given normalize values for a and b, let the notation a[n] denote the
    1.26 +nth digit of a.  Let #a be the number of significant figures of a (not
    1.27 +including any leading zeroes).
    1.28 +
    1.29 +	Let R = 0
    1.30 +	Let p = #a - 1
    1.31 +
    1.32 +	while(p >= 0)
    1.33 +	  do
    1.34 +	    R = (R * radix) + a[p]
    1.35 +	    p = p - 1
    1.36 +	  while(R < b and p >= 0)
    1.37 +
    1.38 +	  if(R < b)
    1.39 +	    break
    1.40 +
    1.41 +	  q = (R[#R - 1] * radix) + R[#R - 2]
    1.42 +	  q = q / b[#b - 1]
    1.43 +
    1.44 +	  T = b * q
    1.45 +
    1.46 +	  while(T > L)
    1.47 +	    q = q - 1
    1.48 +	    T = T - b
    1.49 +	  endwhile
    1.50 +
    1.51 +	  L = L - T
    1.52 +
    1.53 +	  Q = (Q * radix) + q
    1.54 +
    1.55 +	endwhile
    1.56 +
    1.57 +At this point, Q is the quotient, and R is the normalized remainder.
    1.58 +To denormalize R, compute:
    1.59 +
    1.60 +	R = (R / d)
    1.61 +
    1.62 +At this point, you are finished.
    1.63 +
    1.64 +------------------------------------------------------------------
    1.65 + This Source Code Form is subject to the terms of the Mozilla Public
    1.66 + # License, v. 2.0. If a copy of the MPL was not distributed with this
    1.67 + # file, You can obtain one at http://mozilla.org/MPL/2.0/.

mercurial