mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
fix zero being power of two (#1684)
This commit is contained in:
parent
69058c126d
commit
9f533fb7ae
@ -27,7 +27,7 @@ func CeilDiv8(n int) int {
|
||||
// IsPowerOf2 returns true if n is an
|
||||
// exact power of two. False otherwise.
|
||||
func IsPowerOf2(n uint64) bool {
|
||||
return (n & (n - 1)) == 0
|
||||
return n != 0 && (n&(n-1)) == 0
|
||||
}
|
||||
|
||||
// PowerOf2 returns an integer that is the provided
|
||||
|
@ -95,6 +95,10 @@ func TestIsPowerOf2(t *testing.T) {
|
||||
a: 1024,
|
||||
b: true,
|
||||
},
|
||||
{
|
||||
a: 0,
|
||||
b: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if tt.b != IsPowerOf2(tt.a) {
|
||||
|
Loading…
Reference in New Issue
Block a user