diff --git a/shared/mathutil/math_helper.go b/shared/mathutil/math_helper.go index 2d01ebe67..b1d147b6e 100644 --- a/shared/mathutil/math_helper.go +++ b/shared/mathutil/math_helper.go @@ -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 diff --git a/shared/mathutil/math_helper_test.go b/shared/mathutil/math_helper_test.go index 56c4a76a1..dc4516c42 100644 --- a/shared/mathutil/math_helper_test.go +++ b/shared/mathutil/math_helper_test.go @@ -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) {