Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bls/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func initGlobals() {
}

func IsPowerOfTwo(v uint64) bool {
return v&(v-1) == 0
return v != 0 && v&(v-1) == 0
}

func EvalPolyAtUnoptimized(dst *Fr, coeffs []Fr, x *Fr) {
Expand Down
48 changes: 48 additions & 0 deletions bls/globals_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package bls

import (
"testing"
)

func TestIsPowerOfTwo(t *testing.T) {
testCases := []struct {
name string
input uint64
expected bool
}{
{
name: "0 is not a power of 2",
input: 0,
expected: false,
},
{
name: "2^0 = 1",
input: 1,
expected: true,
},
{
name: "2^1 = 2",
input: 2,
expected: true,
},
{
name: "3 is not a power of 2",
input: 3,
expected: false,
},
{
name: "2^2 = 4",
input: 4,
expected: true,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := IsPowerOfTwo(tc.input)
if result != tc.expected {
t.Fatalf("IsPowerOfTwo(%d) = %v; want %v", tc.input, result, tc.expected)
}
})
}
}