Skip to content

BigInt AddAssign<isize> with negative addend is off by 2^32 or 2^64 #132

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

Closed
HactarCE opened this issue Jan 25, 2020 · 2 comments · Fixed by #133
Closed

BigInt AddAssign<isize> with negative addend is off by 2^32 or 2^64 #132

HactarCE opened this issue Jan 25, 2020 · 2 comments · Fixed by #133

Comments

@HactarCE
Copy link
Contributor

let mut x: BigInt = 0.into();
let y: isize = -1;
x += y;
assert_eq!(BigInt::from(-1), x); // fails
// x is actually 2^64-1

x + y gives the proper result (-1), and if y is i32 or i64 it works as expected, but isize somehow breaks things. When compiled for 64-bit the result is off by 2^64, and for 32-bit it is off by 2^32.

@cuviper
Copy link
Member

cuviper commented Jan 27, 2020

Thank you for the fix in #133 -- I've also released this as num-bigint 0.2.6.

@HactarCE
Copy link
Contributor Author

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants