Skip to content

Fix IBig >> by >= bit length on DoubleWord magnitudes - #61

Merged
cmpute merged 2 commits into
cmpute:masterfrom
DRMacIver:fix-ibig-shr-dword-boundary
Jun 1, 2026
Merged

Fix IBig >> by >= bit length on DoubleWord magnitudes#61
cmpute merged 2 commits into
cmpute:masterfrom
DRMacIver:fix-ibig-shr-dword-boundary

Conversation

@DRMacIver

Copy link
Copy Markdown
Contributor

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.

@cmpute

cmpute commented May 31, 2026

Copy link
Copy Markdown
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
DRMacIver force-pushed the fix-ibig-shr-dword-boundary branch from 6290d5a to f810397 Compare May 31, 2026 07:39
@DRMacIver

Copy link
Copy Markdown
Contributor Author

Sure thing! Done.

@cmpute

cmpute commented Jun 1, 2026

Copy link
Copy Markdown
Owner

LGTM, thanks for the fix!

@cmpute
cmpute merged commit 7d0499f into cmpute:master Jun 1, 2026
23 of 26 checks passed
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 this pull request may close these issues.

2 participants