-
Notifications
You must be signed in to change notification settings - Fork 192
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
Get/set n-th bit of BigUint
and BigInt
#183
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! The two's complement stuff is a bit hairy, as expected, but I don't see any problem with it.
@cuviper I have now updated the PR with a more efficient implementation of I have also implemented a special case for |
@cuviper it's been a while since the last review :) Is this PR all good? (asking, since I am waiting for this feature) |
32-bit targets would fail to convert that to a `usize` digit index, but we can reasonably say that all bits are false at that point.
I added a couple tweaks to the edge cases of bors r+ |
183: Get/set n-th bit of `BigUint` and `BigInt` r=cuviper a=janmarthedal This PR implements `bit` and `set_bit` for `BigUint` and `BigInt`. The method names have been chosen to match those of Ramp (https://docs.rs/ramp/0.5.9/ramp/int/struct.Int.html#method.bit). For `BigInt` the implementation uses the number's two's complement representation when the number is negative. This matches what libraries like Ramp or languages like Python do. Resolves #172 Co-authored-by: Jan Marthedal Rasmussen <jan@janmr.com> Co-authored-by: Josh Stone <cuviper@gmail.com>
Build failed: |
bors r+ |
This PR implements
bit
andset_bit
forBigUint
andBigInt
.The method names have been chosen to match those of Ramp (https://docs.rs/ramp/0.5.9/ramp/int/struct.Int.html#method.bit).
For
BigInt
the implementation uses the number's two's complement representation when the number is negative. This matches what libraries like Ramp or languages like Python do.Resolves #172