1
0
mirror of https://github.com/golang/go synced 2024-11-24 23:17:57 -07:00

math/big: various cleanups

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/6295072
This commit is contained in:
Robert Griesemer 2012-06-13 09:37:47 -07:00
parent 38735b957c
commit b7c5e23df0

View File

@ -493,14 +493,9 @@ func (z nat) div(z2, u, v nat) (q, r nat) {
} }
if len(v) == 1 { if len(v) == 1 {
var rprime Word var r2 Word
q, rprime = z.divW(u, v[0]) q, r2 = z.divW(u, v[0])
if rprime > 0 { r = z2.setWord(r2)
r = z2.make(1)
r[0] = rprime
} else {
r = z2.make(0)
}
return return
} }
@ -1011,7 +1006,7 @@ func trailingZeroBits(x Word) uint {
case 64: case 64:
return uint(deBruijn64Lookup[((x&-x)*(deBruijn64&_M))>>58]) return uint(deBruijn64Lookup[((x&-x)*(deBruijn64&_M))>>58])
default: default:
panic("Unknown word size") panic("unknown word size")
} }
return 0 return 0
@ -1198,17 +1193,19 @@ func (z nat) random(rand *rand.Rand, limit nat, n int) nat {
mask := Word((1 << bitLengthOfMSW) - 1) mask := Word((1 << bitLengthOfMSW) - 1)
for { for {
for i := range z { switch _W {
switch _W { case 32:
case 32: for i := range z {
z[i] = Word(rand.Uint32()) z[i] = Word(rand.Uint32())
case 64: }
case 64:
for i := range z {
z[i] = Word(rand.Uint32()) | Word(rand.Uint32())<<32 z[i] = Word(rand.Uint32()) | Word(rand.Uint32())<<32
} }
default:
panic("unknown word size")
} }
z[len(limit)-1] &= mask z[len(limit)-1] &= mask
if z.cmp(limit) < 0 { if z.cmp(limit) < 0 {
break break
} }