github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/internal/math.go (about)

     1  package internal
     2  
     3  import "golang.org/x/exp/constraints"
     4  
     5  // Align returns 'n' updated to 'alignment' boundary.
     6  func Align[I constraints.Integer](n, alignment I) I {
     7  	return (n + alignment - 1) / alignment * alignment
     8  }
     9  
    10  // IsPow returns true if n is a power of two.
    11  func IsPow[I constraints.Integer](n I) bool {
    12  	return n != 0 && (n&(n-1)) == 0
    13  }