diff options
author | Adam Langley <agl@golang.org> | 2009-11-18 19:26:12 -0800 |
---|---|---|
committer | Adam Langley <agl@golang.org> | 2009-11-18 19:26:12 -0800 |
commit | 37c0687beab02ea09cda7bff6e39a04fb71d01ca (patch) | |
tree | 9acc4fdbb09c2684f9e67331a3e5522b831f689e /src/pkg/big | |
parent | a1dec403e8dbcfb4efe93c34eadbb2b2e0b17dc3 (diff) | |
download | golang-37c0687beab02ea09cda7bff6e39a04fb71d01ca.tar.gz |
big: fix large division.
I missed a case.
R=rsc, agl
CC=golang-dev
http://codereview.appspot.com/156092
Diffstat (limited to 'src/pkg/big')
-rw-r--r-- | src/pkg/big/nat.go | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/pkg/big/nat.go b/src/pkg/big/nat.go index 8fabd7c8d..7fad9f829 100644 --- a/src/pkg/big/nat.go +++ b/src/pkg/big/nat.go @@ -310,20 +310,26 @@ func divLargeNN(z, z2, uIn, v []Word) (q, r []Word) { // D2. for j := m; j >= 0; j-- { // D3. - qhat, rhat := divWW_g(u[j+n], u[j+n-1], v[n-1]); - - // x1 | x2 = q̂v_{n-2} - x1, x2 := mulWW_g(qhat, v[n-2]); - // test if q̂v_{n-2} > br̂ + u_{j+n-2} - for greaterThan(x1, x2, rhat, u[j+n-2]) { - qhat--; - prevRhat := rhat; - rhat += v[n-1]; - // v[n-1] >= 0, so this tests for overflow. - if rhat < prevRhat { - break + var qhat Word; + if u[j+n] == v[n-1] { + qhat = _B - 1 + } else { + var rhat Word; + qhat, rhat = divWW_g(u[j+n], u[j+n-1], v[n-1]); + + // x1 | x2 = q̂v_{n-2} + x1, x2 := mulWW_g(qhat, v[n-2]); + // test if q̂v_{n-2} > br̂ + u_{j+n-2} + for greaterThan(x1, x2, rhat, u[j+n-2]) { + qhat--; + prevRhat := rhat; + rhat += v[n-1]; + // v[n-1] >= 0, so this tests for overflow. + if rhat < prevRhat { + break + } + x1, x2 = mulWW_g(qhat, v[n-2]); } - x1, x2 = mulWW_g(qhat, v[n-2]); } // D4. |