mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
Remove NextPowerOf2 (for uint64)
This commit is contained in:
parent
1df0854193
commit
091cc215fb
@ -19,21 +19,16 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NextPowerOf2(x uint64) uint64 {
|
func NextPowerOf2Int(x int) int {
|
||||||
x -= 1
|
x -= 1
|
||||||
x |= (x >> 1)
|
x |= (x >> 1)
|
||||||
x |= (x >> 2)
|
x |= (x >> 2)
|
||||||
x |= (x >> 4)
|
x |= (x >> 4)
|
||||||
x |= (x >> 8)
|
x |= (x >> 8)
|
||||||
x |= (x >> 16)
|
x |= (x >> 16)
|
||||||
x |= (x >> 32)
|
|
||||||
return x + 1
|
return x + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func NextPowerOf2Int(size int) int {
|
|
||||||
return int(NextPowerOf2(uint64(size)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func RGBA(clr color.Color) (r, g, b, a float64) {
|
func RGBA(clr color.Color) (r, g, b, a float64) {
|
||||||
cr, cg, cb, ca := clr.RGBA()
|
cr, cg, cb, ca := clr.RGBA()
|
||||||
const max = math.MaxUint16
|
const max = math.MaxUint16
|
||||||
|
@ -21,8 +21,8 @@ import (
|
|||||||
|
|
||||||
func TestNextPowerOf2(t *testing.T) {
|
func TestNextPowerOf2(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
expected uint64
|
expected int
|
||||||
arg uint64
|
arg int
|
||||||
}{
|
}{
|
||||||
{256, 255},
|
{256, 255},
|
||||||
{256, 256},
|
{256, 256},
|
||||||
@ -30,7 +30,7 @@ func TestNextPowerOf2(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
got := NextPowerOf2(testCase.arg)
|
got := NextPowerOf2Int(testCase.arg)
|
||||||
wanted := testCase.expected
|
wanted := testCase.expected
|
||||||
if wanted != got {
|
if wanted != got {
|
||||||
t.Errorf("Clp(%d) = %d, wanted %d", testCase.arg, got, wanted)
|
t.Errorf("Clp(%d) = %d, wanted %d", testCase.arg, got, wanted)
|
||||||
|
Loading…
Reference in New Issue
Block a user