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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 Division
michael@0 2
michael@0 3 This describes the division algorithm used by the MPI library.
michael@0 4
michael@0 5 Input: a, b; a > b
michael@0 6 Compute: Q, R; a = Qb + R
michael@0 7
michael@0 8 The input numbers are normalized so that the high-order digit of b is
michael@0 9 at least half the radix. This guarantees that we have a reasonable
michael@0 10 way to guess at the digits of the quotient (this method was taken from
michael@0 11 Knuth, vol. 2, with adaptations).
michael@0 12
michael@0 13 To normalize, test the high-order digit of b. If it is less than half
michael@0 14 the radix, multiply both a and b by d, where:
michael@0 15
michael@0 16 radix - 1
michael@0 17 d = -----------
michael@0 18 bmax + 1
michael@0 19
michael@0 20 ...where bmax is the high-order digit of b. Otherwise, set d = 1.
michael@0 21
michael@0 22 Given normalize values for a and b, let the notation a[n] denote the
michael@0 23 nth digit of a. Let #a be the number of significant figures of a (not
michael@0 24 including any leading zeroes).
michael@0 25
michael@0 26 Let R = 0
michael@0 27 Let p = #a - 1
michael@0 28
michael@0 29 while(p >= 0)
michael@0 30 do
michael@0 31 R = (R * radix) + a[p]
michael@0 32 p = p - 1
michael@0 33 while(R < b and p >= 0)
michael@0 34
michael@0 35 if(R < b)
michael@0 36 break
michael@0 37
michael@0 38 q = (R[#R - 1] * radix) + R[#R - 2]
michael@0 39 q = q / b[#b - 1]
michael@0 40
michael@0 41 T = b * q
michael@0 42
michael@0 43 while(T > L)
michael@0 44 q = q - 1
michael@0 45 T = T - b
michael@0 46 endwhile
michael@0 47
michael@0 48 L = L - T
michael@0 49
michael@0 50 Q = (Q * radix) + q
michael@0 51
michael@0 52 endwhile
michael@0 53
michael@0 54 At this point, Q is the quotient, and R is the normalized remainder.
michael@0 55 To denormalize R, compute:
michael@0 56
michael@0 57 R = (R / d)
michael@0 58
michael@0 59 At this point, you are finished.
michael@0 60
michael@0 61 ------------------------------------------------------------------
michael@0 62 This Source Code Form is subject to the terms of the Mozilla Public
michael@0 63 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 64 # file, You can obtain one at http://mozilla.org/MPL/2.0/.

mercurial