Skip to content

fix off by 1 error in ShiftRight#208

Merged
lemire merged 1 commit intobits-and-blooms:masterfrom
whisk:master
Oct 12, 2025
Merged

fix off by 1 error in ShiftRight#208
lemire merged 1 commit intobits-and-blooms:masterfrom
whisk:master

Conversation

@whisk
Copy link
Copy Markdown
Contributor

@whisk whisk commented Oct 12, 2025

Description

b := New(0)
b.Set(N)
b.ShiftRight(N) // expect to have the zero bit set, as (2^N) >> N == 1
b.Test(0) // false...

Fix

It seems like an off by one error in ShiftRight. We should empty the set iff the shift distance exceeds the number of top set bit. When the shift distance equals to the top set bit, that is the only bit what is left after the shift.
It also required adjusting one existing test case.

@lemire lemire merged commit 996a67e into bits-and-blooms:master Oct 12, 2025
27 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