The bug was caused by using self.len().ilog2() instead of ilog2() + 1 whenever the length was a power of two. Suppose for example the length is 8, a power of two. Then the popcount of 0b1111_1111 is 8 = 0b1000 which requires 4 bits to represent. So we need to use ilog2() + 1 when it's a power of two.
The bug was caused by using
self.len().ilog2()
instead ofilog2() + 1
whenever the length was a power of two. Suppose for example the length is8
, a power of two. Then the popcount of0b1111_1111
is8 = 0b1000
which requires4
bits to represent. So we need to useilog2() + 1
when it's a power of two.