big: use fast shift routines
- fixed a couple of bugs in the process
(shift right was incorrect for negative numbers)
- added more tests and made some tests more robust
- changed pidigits back to using shifts to multiply
by 2 instead of add
This improves pidigit -s -n 10000 by approx. 5%:
user 0m6.496s (old)
user 0m6.156s (new)
R=rsc
CC=golang-dev
https://golang.org/cl/963044
diff --git a/test/bench/pidigits.go b/test/bench/pidigits.go
index 3e455dc..a055150 100644
--- a/test/bench/pidigits.go
+++ b/test/bench/pidigits.go
@@ -63,7 +63,7 @@
}
// Compute (numer * 3 + accum) / denom
- tmp1.Add(numer, numer) // tmp1.Lsh(numer, 1)
+ tmp1.Lsh(numer, 1)
tmp1.Add(tmp1, numer)
tmp1.Add(tmp1, accum)
tmp1.DivMod(tmp1, denom, tmp2)
@@ -84,7 +84,7 @@
y2.New(k*2 + 1)
bigk.New(k)
- tmp1.Add(numer, numer) // tmp1.Lsh(numer, 1)
+ tmp1.Lsh(numer, 1)
accum.Add(accum, tmp1)
accum.Mul(accum, y2)
numer.Mul(numer, bigk)