Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math/big: AndNot(x,y) doesn't work when x is positive and y is negative #9609

Closed
randall77 opened this issue Jan 16, 2015 · 1 comment
Closed

Comments

@randall77
Copy link
Contributor

package main

import (
"fmt"
"math/big"
)

func main() {
fmt.Println(new(big.Int).AndNot(big.NewInt(0xff), big.NewInt(-1)))
}

This should print 0. It does print 2.
The bug is in math/big/int.go:893, it should use sub, not add, as the comment in the previous line specifies.

@randall77 randall77 self-assigned this Jan 16, 2015
@randall77 randall77 added this to the Go1.4.2 milestone Jan 16, 2015
@mikioh mikioh changed the title math/big.AndNot(x,y) doesn't work when x is positive and y is negative math/big: AndNot(x,y) doesn't work when x is positive and y is negative Jan 16, 2015
gopherbot pushed a commit that referenced this issue Jan 17, 2015
Fixes #9607
Related to #9604
Inadvertently found #9609

Change-Id: I8a8ddf84ac72d3e18986fd8e9288734459f3f174
Reviewed-on: https://go-review.googlesource.com/2962
Reviewed-by: Minux Ma <minux@golang.org>
adg pushed a commit that referenced this issue Feb 17, 2015
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 c6ddca2)
Reviewed-on: https://go-review.googlesource.com/5001
@rsc
Copy link
Contributor

rsc commented Feb 18, 2015

Not obvious why this was 1.4.2 worthy.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
The comment says to use (y-1), but then we did add(y.abs, natOne).  We meant sub.

Fixes golang#9609

Change-Id: I4fe4783326ca082c05588310a0af7895a48fc779
Reviewed-on: https://go-review.googlesource.com/2961
Reviewed-by: Robert Griesemer <gri@golang.org>
(cherry picked from commit c6ddca2)
Reviewed-on: https://go-review.googlesource.com/5001
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 26, 2018
The comment says to use (y-1), but then we did add(y.abs, natOne).  We meant sub.

Fixes golang#9609

Change-Id: I4fe4783326ca082c05588310a0af7895a48fc779
Reviewed-on: https://go-review.googlesource.com/2961
Reviewed-by: Robert Griesemer <gri@golang.org>
(cherry picked from commit c6ddca2)
Reviewed-on: https://go-review.googlesource.com/5001
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
The comment says to use (y-1), but then we did add(y.abs, natOne).  We meant sub.

Fixes golang#9609

Change-Id: I4fe4783326ca082c05588310a0af7895a48fc779
Reviewed-on: https://go-review.googlesource.com/2961
Reviewed-by: Robert Griesemer <gri@golang.org>
(cherry picked from commit c6ddca2)
Reviewed-on: https://go-review.googlesource.com/5001
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 20, 2018
The comment says to use (y-1), but then we did add(y.abs, natOne).  We meant sub.

Fixes golang#9609

Change-Id: I4fe4783326ca082c05588310a0af7895a48fc779
Reviewed-on: https://go-review.googlesource.com/2961
Reviewed-by: Robert Griesemer <gri@golang.org>
(cherry picked from commit c6ddca2)
Reviewed-on: https://go-review.googlesource.com/5001
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 30, 2018
The comment says to use (y-1), but then we did add(y.abs, natOne).  We meant sub.

Fixes golang#9609

Change-Id: I4fe4783326ca082c05588310a0af7895a48fc779
Reviewed-on: https://go-review.googlesource.com/2961
Reviewed-by: Robert Griesemer <gri@golang.org>
(cherry picked from commit c6ddca2)
Reviewed-on: https://go-review.googlesource.com/5001
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants