Fix IBig >> by >= bit length on DoubleWord magnitudes - #61
Merged
Conversation
Owner
|
Thanks, could you rebase your edits (including #62) to the latest master? I have fixed the CI (and released a version of dashu because of MSRV bump). |
are_dword_low_bits_nonzero capped its bit window at WORD_BITS instead of DWORD_BITS, so any query asking about bits in the upper word lost them. The arithmetic-shift path for negative values then dropped the floor-rounding correction term, returning 0 instead of -1. Concrete failure: IBig::from(i128::MIN) >> 128 returned 0.
DRMacIver
force-pushed
the
fix-ibig-shr-dword-boundary
branch
from
May 31, 2026 07:39
6290d5a to
f810397
Compare
Contributor
Author
|
Sure thing! Done. |
Owner
|
LGTM, thanks for the fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In this case the intended behaviour seems to be that large shifts of negative numbers round towards -infinity, but instead the sign was getting lost and the integer was truncated to 0.
BTW I found this with some property-based tests using hegel doing differential testing against num-bigint (I wasn't especially looking for bugs in dashu, but I wanted to make some performance optimisations and the tests were there to make sure I didn't break anything). Happy to contribute the test suite if you're interested.