github.com/anacrolix/torrent@v1.61.0/math.go (about)

     1  package torrent
     2  
     3  import (
     4  	"golang.org/x/exp/constraints"
     5  )
     6  
     7  // a/b rounding up
     8  func intCeilDiv[T constraints.Unsigned](a, b T) T {
     9  	// This still sux for negative numbers due to truncating division. But I don't know that we need
    10  	// or that ceil division makes sense for negative numbers.
    11  	return (a + b - 1) / b
    12  }
    13  
    14  func roundToNextMultiple[T constraints.Unsigned](x, multiple T) T {
    15  	return intCeilDiv(x, multiple) * multiple
    16  }