github.com/primecitizens/pcz/std@v0.2.1/core/num/align.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  package num
     5  
     6  // AlignUp rounds n up to multiple of a. a must be a power of 2.
     7  func AlignUp[T Uint](n, a T) T {
     8  	return (n + a - 1) & (^(a - 1))
     9  }
    10  
    11  // AlignDown rounds n down to multiple of a. a must be a power of 2.
    12  func AlignDown[T Uint](n, a T) T {
    13  	return n & (^(a - 1))
    14  }
    15  
    16  func IsPowerOfTwo[T Integer](x T) bool {
    17  	return x&(x-1) == 0
    18  }