Debian Codegraph @

internal/math.go

raw symbols SCIP
1 package internal
2
3 // Align returns 'n' updated to 'alignment' boundary.
4 func Align[I Integer](n, alignment I) I {
5 return (n + alignment - 1) / alignment * alignment
6 }
7
8 // IsPow returns true if n is a power of two.
9 func IsPow[I Integer](n I) bool {
10 return n != 0 && (n&(n-1)) == 0
11 }
12
13 // Between returns the value clamped between a and b.
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 // Integer represents all possible integer types.
25 // Remove when x/exp/constraints is moved to the standard library.
26 type Integer interface {
27 ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
28 }
29
30 // List of integer types known by the Go compiler. Used by TestIntegerConstraint
31 // to warn if a new integer type is introduced. Remove when x/exp/constraints
32 // is moved to the standard library.
33 var integers = []string{"int", "int8", "int16", "int32", "int64", "uint", "uint8", "uint16", "uint32", "uint64", "uintptr"}