Skip to content

Commit

Permalink
fix zero being power of two (#1684)
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvanloon authored and terencechain committed Feb 22, 2019
1 parent 69058c1 commit 9f533fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shared/mathutil/math_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions shared/mathutil/math_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9f533fb

Please sign in to comment.