Fairly correct implementation of right-shift and division with rounding. Also fairly efficient, though I'm sure I'll find some cases where we're generating uncessary overflow checks upon further inspection. Nonetheless, a decent enough start.
The following methods are added to SignedInteger (not BinaryInteger, because the remainder is not generally representable in an UnsignedType when the rounding mode is not .down or .towardZero):
Fairly correct implementation of right-shift and division with rounding. Also fairly efficient, though I'm sure I'll find some cases where we're generating uncessary overflow checks upon further inspection. Nonetheless, a decent enough start.
The methods are added to BinaryInteger:
shifted<Count: BinaryInteger>(right: Count, rounding: RoundingRule) -> Self
divided(by: Self, rounding: RoundingRule) -> Self
The following methods are added to SignedInteger (not BinaryInteger, because the remainder is not generally representable in an UnsignedType when the rounding mode is not
.down
or.towardZero
):remainder(dividingBy: Self, rounding: RoundingRule) -> Self
divded(by: Self, rounding: RoundingRule) -> (quotient: Self, remainder: Self)
The following free function is added:
euclideanDivision<T: BinaryInteger>(_: T, _: T) -> (quotient: Self, remainder: Self)