aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2015-01-15 20:45:07 -0800
committerAndrew Gerrand <adg@golang.org>2015-02-17 06:48:38 +0000
commit5caa9d15f26a088d3c75a183d70d4bf3a355200e (patch)
tree49a48e94ddb580a79fe6d4464babb3f841efe570
parentb64f8f8764e975b98e2c5e0d77a424601ed75c29 (diff)
downloadgo-5caa9d15f26a088d3c75a183d70d4bf3a355200e.tar.gz
go-5caa9d15f26a088d3c75a183d70d4bf3a355200e.zip
[release-branch.go1.4] math/big: bug in AndNot(x,y) for x>0,y<0.
The comment says to use (y-1), but then we did add(y.abs, natOne). We meant sub. Fixes #9609 Change-Id: I4fe4783326ca082c05588310a0af7895a48fc779 Reviewed-on: https://go-review.googlesource.com/2961 Reviewed-by: Robert Griesemer <gri@golang.org> (cherry picked from commit c6ddca2aec4218e1af7f51fad3b761afb33b4c20) Reviewed-on: https://go-review.googlesource.com/5001
-rw-r--r--src/math/big/int.go2
-rw-r--r--src/math/big/int_test.go1
2 files changed, 2 insertions, 1 deletions
diff --git a/src/math/big/int.go b/src/math/big/int.go
index d22e39e7c94..ade5c2fc8cd 100644
--- a/src/math/big/int.go
+++ b/src/math/big/int.go
@@ -887,7 +887,7 @@ func (z *Int) AndNot(x, y *Int) *Int {
}
// x &^ (-y) == x &^ ^(y-1) == x & (y-1)
- y1 := nat(nil).add(y.abs, natOne)
+ y1 := nat(nil).sub(y.abs, natOne)
z.abs = z.abs.and(x.abs, y1)
z.neg = false
return z
diff --git a/src/math/big/int_test.go b/src/math/big/int_test.go
index 6070cf325d2..2d762dbc89f 100644
--- a/src/math/big/int_test.go
+++ b/src/math/big/int_test.go
@@ -1201,6 +1201,7 @@ var bitwiseTests = []struct {
{"-0x01", "-0x01", "-0x01", "-0x01", "0x00", "0x00"},
{"0x07", "0x08", "0x00", "0x0f", "0x0f", "0x07"},
{"0x05", "0x0f", "0x05", "0x0f", "0x0a", "0x00"},
+ {"0xff", "-0x0a", "0xf6", "-0x01", "-0xf7", "0x09"},
{"0x013ff6", "0x9a4e", "0x1a46", "0x01bffe", "0x01a5b8", "0x0125b0"},
{"-0x013ff6", "0x9a4e", "0x800a", "-0x0125b2", "-0x01a5bc", "-0x01c000"},
{"-0x013ff6", "-0x9a4e", "-0x01bffe", "-0x1a46", "0x01a5b8", "0x8008"},