FixedWidthInteger

extension FixedWidthInteger
  • Divide the double-width integer dividend by self and return the quotient and remainder.

    Requires

    dividend.high < self, so that the result will fit in a single digit.

    Complexity

    O(1) with 2 divisions, 6 multiplications and ~12 or so additions/subtractions.

    Declaration

    Swift

    internal func fastDividingFullWidth(_ dividend: (high: Self, low: Self.Magnitude)) -> (quotient: Self, remainder: Self)
  • Return the quotient of the 3/2-word division x/y as a single word.

    Requires

    (x.0, x.1) <= y && y.0.high != 0

    Declaration

    Swift

    static func approximateQuotient(dividing x: (Self, Self, Self), by y: (Self, Self)) -> Self

    Return Value

    The exact value when it fits in a single word, otherwise Self.