| 1 |
package internal |
| 2 |
|
| 3 |
|
| 4 |
func Align[I Integer](n, alignment I) I { |
| 5 |
return (n + alignment - 1) / alignment * alignment |
| 6 |
} |
| 7 |
|
| 8 |
|
| 9 |
func IsPow[I Integer](n I) bool { |
| 10 |
return n != 0 && (n&(n-1)) == 0 |
| 11 |
} |
| 12 |
|
| 13 |
|
| 14 |
func Between[I Integer](val, a, b I) I { |
| 15 |
lower, upper := a, b |
| 16 |
if lower > upper { |
| 17 |
upper, lower = a, b |
| 18 |
} |
| 19 |
|
| 20 |
val = min(val, upper) |
| 21 |
return max(val, lower) |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
type Integer interface { |
| 27 |
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
var integers = []string{"int", "int8", "int16", "int32", "int64", "uint", "uint8", "uint16", "uint32", "uint64", "uintptr"} |