Commit fcf063b
committed
refactor: off-by-one error in binary_count_trailing_zeros for zero input
"The function returns `0` for `a == 0`, but mathematically, trailing zeros in binary representation of 0 are undefined (or conventionally treated as infinite). While `log2(a & -a)` fails for `a=0`, the current fallback to `0` is inconsistent with the documented behavior: `binary_count_trailing_zeros(16)` returns `4`, but `0` has infinitely many trailing zeros — returning `0` is misleading and could cause bugs in algorithms relying on this (e.g., bit manipulation loops expecting correct trailing zero counts)."
Signed-off-by: Zendy <50132805+zendy199x@users.noreply.github.com>1 parent 841e947 commit fcf063b
1 file changed
+5
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | | - | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | | - | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
0 commit comments