Remove NextPowerOf2 (for uint64)

This commit is contained in:
Hajime Hoshi 2015-01-03 01:46:25 +09:00
parent 1df0854193
commit 091cc215fb
2 changed files with 4 additions and 9 deletions

View File

@ -19,21 +19,16 @@ import (
"math"
)
func NextPowerOf2(x uint64) uint64 {
func NextPowerOf2Int(x int) int {
x -= 1
x |= (x >> 1)
x |= (x >> 2)
x |= (x >> 4)
x |= (x >> 8)
x |= (x >> 16)
x |= (x >> 32)
return x + 1
}
func NextPowerOf2Int(size int) int {
return int(NextPowerOf2(uint64(size)))
}
func RGBA(clr color.Color) (r, g, b, a float64) {
cr, cg, cb, ca := clr.RGBA()
const max = math.MaxUint16

View File

@ -21,8 +21,8 @@ import (
func TestNextPowerOf2(t *testing.T) {
testCases := []struct {
expected uint64
arg uint64
expected int
arg int
}{
{256, 255},
{256, 256},
@ -30,7 +30,7 @@ func TestNextPowerOf2(t *testing.T) {
}
for _, testCase := range testCases {
got := NextPowerOf2(testCase.arg)
got := NextPowerOf2Int(testCase.arg)
wanted := testCase.expected
if wanted != got {
t.Errorf("Clp(%d) = %d, wanted %d", testCase.arg, got, wanted)