'Return a / b, to context.prec precision.
divmod:
0 => true division
1 => (a //b, a%b)
2 => a //b
3 => a%b
Actually, if divmod is 2 or 3 a tuple is returned, but errors for
computing the other value are not raised.'

def _divide(self, other, divmod=0, context=None):

    other = _convert_other(other)
    if (context is None):
        context = getcontext()
    sign = (self._sign ^ other._sign)
    if (self._is_special or other._is_special):
        ans = self._check_nans(other, context)
        if ans:
            if divmod:
                return (ans, ans)
            return ans
        if (self._isinfinity() and other._isinfinity()):
            if divmod:
                return (context._raise_error(InvalidOperation, '(+-)INF    //    (+-)INF'), context._raise_error(InvalidOperation, '(+-)INF    %    (+-)INF'))
            return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF')
        if self._isinfinity():
            if (divmod == 1):
                return (Infsign[sign], context._raise_error(InvalidOperation, 'INF    %    x'))
            elif (divmod == 2):
                return (Infsign[sign], NaN)
            elif (divmod == 3):
                return (Infsign[sign], context._raise_error(InvalidOperation, 'INF    %    x'))
            return Infsign[sign]
        if other._isinfinity():
            if divmod:
                return (Decimal((sign, (0,), 0)), Decimal(self))
            context._raise_error(Clamped, 'Division    by    infinity')
            return Decimal((sign, (0,), context.Etiny()))
    if ((not self) and (not other)):
        if divmod:
            return context._raise_error(DivisionUndefined, '0    /    0', 1)
        return context._raise_error(DivisionUndefined, '0    /    0')
    if (not self):
        if divmod:
            otherside = Decimal(self)
            otherside._exp = min(self._exp, other._exp)
            return (Decimal((sign, (0,), 0)), otherside)
        exp = (self._exp - other._exp)
        if (exp < context.Etiny()):
            exp = context.Etiny()
            context._raise_error(Clamped, '0e-x    /    y')
        if (exp > context.Emax):
            exp = context.Emax
            context._raise_error(Clamped, '0e+x    /    y')
        return Decimal((sign, (0,), exp))
    if (not other):
        if divmod:
            return context._raise_error(DivisionByZero, 'divmod(x,0)', sign, 1)
        return context._raise_error(DivisionByZero, 'x    /    0', sign)
    shouldround = (context._rounding_decision == ALWAYS_ROUND)
    if (divmod and (self.__abs__(0, context) < other.__abs__(0, context))):
        if ((divmod == 1) or (divmod == 3)):
            exp = min(self._exp, other._exp)
            ans2 = self._rescale(exp, context=context, watchexp=0)
            if shouldround:
                ans2 = ans2._fix(context)
            return (Decimal((sign, (0,), 0)), ans2)
        elif (divmod == 2):
            return (Decimal((sign, (0,), 0)), Decimal(self))
    op1 = _WorkRep(self)
    op2 = _WorkRep(other)
    (op1, op2, adjust) = _adjust_coefficients(op1, op2)
    res = _WorkRep((sign, 0, (op1.exp - op2.exp)))
    if (divmod and (res.exp > (context.prec + 1))):
        return context._raise_error(DivisionImpossible)
    prec_limit = (10 ** context.prec)
    while 1:
        while (op2.int <= op1.int):
            res.int += 1
            op1.int -= op2.int
        if ((res.exp == 0) and divmod):
            if ((res.int >= prec_limit) and shouldround):
                return context._raise_error(DivisionImpossible)
            otherside = Decimal(op1)
            frozen = context._ignore_all_flags()
            exp = min(self._exp, other._exp)
            otherside = otherside._rescale(exp, context=context, watchexp=0)
            context._regard_flags(*frozen)
            if shouldround:
                otherside = otherside._fix(context)
            return (Decimal(res), otherside)
        if ((op1.int == 0) and (adjust >= 0) and (not divmod)):
            break
        if ((res.int >= prec_limit) and shouldround):
            if divmod:
                return context._raise_error(DivisionImpossible)
            shouldround = 1
            if (op1.int != 0):
                res.int *= 10
                res.int += 1
                res.exp -= 1
            break
        res.int *= 10
        res.exp -= 1
        adjust += 1
        op1.int *= 10
        op1.exp -= 1
        if ((res.exp == 0) and divmod and (op2.int > op1.int)):
            if ((res.int >= prec_limit) and shouldround):
                return context._raise_error(DivisionImpossible)
            otherside = Decimal(op1)
            frozen = context._ignore_all_flags()
            exp = min(self._exp, other._exp)
            otherside = otherside._rescale(exp, context=context)
            context._regard_flags(*frozen)
            return (Decimal(res), otherside)
    ans = Decimal(res)
    if shouldround:
        ans = ans._fix(context)
    return ans
