big: completed set of Int division routines & cleanups
- renamed Len -> BitLen, simplified implementation
- renamed old Div, Mod, DivMod -> Que, Rem, QuoRem
- implemented Div, Mod, DivMod (Euclidian definition, more
useful in a mathematical context)
- fixed a bug in Exp (-0 was possible)
- added extra tests to check normalized results everywhere
- uniformly set Int.neg flag at the end of computations
- minor cosmetic cleanups
- ran all tests
R=rsc
CC=golang-dev
https://golang.org/cl/1091041
diff --git a/src/pkg/big/nat.go b/src/pkg/big/nat.go
index fd4c49f..1cad237 100755
--- a/src/pkg/big/nat.go
+++ b/src/pkg/big/nat.go
@@ -356,7 +356,7 @@
// alias returns true if x and y share the same base array.
func alias(x, y nat) bool {
- return &x[0:cap(x)][cap(x)-1] == &y[0:cap(y)][cap(y)-1]
+ return cap(x) > 0 && cap(y) > 0 && &x[0:cap(x)][cap(x)-1] == &y[0:cap(y)][cap(y)-1]
}
@@ -412,7 +412,7 @@
// m >= n > 1
// determine if z can be reused
- if len(z) > 0 && (alias(z, x) || alias(z, y)) {
+ if alias(z, x) || alias(z, y) {
z = nil // z is an alias for x or y - cannot reuse
}
@@ -757,7 +757,7 @@
// determine if z can be reused
// TODO(gri) change shlVW so we don't need this
- if len(z) > 0 && alias(z, x) {
+ if alias(z, x) {
z = nil // z is an alias for x - cannot reuse
}
@@ -780,7 +780,7 @@
// determine if z can be reused
// TODO(gri) change shrVW so we don't need this
- if len(z) > 0 && alias(z, x) {
+ if alias(z, x) {
z = nil // z is an alias for x - cannot reuse
}