forked from KorokEngine/Korok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i32.go
68 lines (59 loc) · 924 Bytes
/
i32.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package math
// types for int/int32/int16...
func U32Clamp(v, low, high uint32) uint32 {
if v < low {
return low
}
if v > high {
return high
}
return v
}
func U32Min(a, b uint32) uint32 {
if a < b {
return a
}
return b
}
func U32Max(a, b uint32) uint32 {
if a < b {
return b
}
return a
}
func U16Clamp(v, low, high uint16) uint16 {
if v < low {
return low
}
if v > high {
return high
}
return v
}
func U16Min(a, b uint16) uint16 {
if a < b {
return a
}
return b
}
func U16Max(a, b uint16) uint16 {
if a < b {
return b
}
return a
}
// Pow2 returns the first power-of-two value >= to n.
// This can be used to create suitable Texture dimensions.
func Pow2(x uint32) uint32 {
x--
x |= x >> 1
x |= x >> 2
x |= x >> 4
x |= x >> 8
x |= x >> 16
return x + 1
}
// IsPow2 returns true if the given value if a power-of-two.
func IsPow2(x uint32) bool {
return (x & (x-1)) == 0
}