github.com/itsabgr/go-handy@v0.0.0-20220724000257-022d51f2b9c6/arch.go (about)

     1  package handy
     2  
     3  import (
     4  	"golang.org/x/exp/constraints"
     5  	"unsafe"
     6  )
     7  
     8  //MaxUint is max uint value
     9  const MaxUint = ^uint(0)
    10  
    11  //MaxInt is max int value
    12  const MaxInt = int(MaxUint >> 1)
    13  
    14  //UintptrSize is memory size of uintptr
    15  const UintptrSize = unsafe.Sizeof(uintptr(0))
    16  
    17  //Bits return bit size of any integer
    18  func Bits[T constraints.Integer](n T) int {
    19  	n = 0
    20  	n = ^n
    21  	i := 0
    22  	for ; n<<i != 0; i++ {
    23  	}
    24  	return i
    25  }