Thank you all. I'll try and see if I'll actually need anything more than this:

```
extension FixedWidthInteger {
func roundedUp(toMultipleOf powerOfTwo: Self) -> Self {
precondition(powerOfTwo > 0 && powerOfTwo & (powerOfTwo &- 1) == 0)
return (self + (powerOfTwo &- 1)) & (0 &- powerOfTwo)
}
func roundedDown(toMultipleOf powerOfTwo: Self) -> Self {
precondition(powerOfTwo > 0 && powerOfTwo & (powerOfTwo &- 1) == 0)
return self & (0 &- powerOfTwo)
}
func roundedUpToPowerOfTwo() -> Self {
precondition(self > 0)
let shifts = bitWidth &- leadingZeroBitCount
return nonzeroBitCount == 1 ? self : 1 &<< shifts
}
}
```

(That is, rounding up and down only to multiples which are powers of two, and only rounding up to powers of two.)

I do think it would be nice to have them on floating point types as well (eg snap to grid in a graphics application). But I guess the naming and semantics would be less obvious for floating point types.

The example of snapping to a 2D grid is a good one because it nicely demonstrates a lot of various related needs. For example rounding both up and down (enlarge a rect so that it snaps to the closest grid points, grid cell size being eg 0.25 units) as well as rounding to nearest (snap a point to the nearest grid point).

Here's a quick attempt at using `remainder(dividingBy:)`

and `truncatingRemainder(dividingBy:)`

to implement the various "rounding to multiple of", not sure if it works as expected:

```
extension BinaryFloatingPoint {
func roundedToNearest(multipleOf m: Self) -> Self {
return self - self.remainder(dividingBy: m)
}
func roundedTowardZero(toMultipleOf m: Self) -> Self {
return self - self.truncatingRemainder(dividingBy: m)
}
func roundedAwayFromZero(toMultipleOf m: Self) -> Self {
let s = self >= 0 ? (self + m).nextDown : (self - m).nextUp
return s - s.truncatingRemainder(dividingBy: m)
}
func roundedDown(toMultipleOf m: Self) -> Self {
return (self < 0) ? self.roundedAwayFromZero(toMultipleOf: m)
: self.roundedTowardZero(toMultipleOf: m)
}
func roundedUp(toMultipleOf m: Self) -> Self {
return (self > 0) ? self.roundedAwayFromZero(toMultipleOf: m)
: self.roundedTowardZero(toMultipleOf: m)
}
}
```

EDIT: No, these doesn't work correctly, for example:

```
print(Float(2).nextUp.roundedUp(toMultipleOf: 2.0)) // Prints 2.0, should be 4.0
```

And, although probably much less needed, I guess one interpretation of binary floating point number "rounded toward zero to power of two" is available for free via `.binade`

.