Return (self // other, self % other), to context.prec precision. Assumes that neither self nor other is a NaN, that self is not infinite and that other is nonzero.
(self, other, context)
| 1391 | return ans._fix(context) |
| 1392 | |
| 1393 | def _divide(self, other, context): |
| 1394 | """Return (self // other, self % other), to context.prec precision. |
| 1395 | |
| 1396 | Assumes that neither self nor other is a NaN, that self is not |
| 1397 | infinite and that other is nonzero. |
| 1398 | """ |
| 1399 | sign = self._sign ^ other._sign |
| 1400 | if other._isinfinity(): |
| 1401 | ideal_exp = self._exp |
| 1402 | else: |
| 1403 | ideal_exp = min(self._exp, other._exp) |
| 1404 | |
| 1405 | expdiff = self.adjusted() - other.adjusted() |
| 1406 | if not self or other._isinfinity() or expdiff <= -2: |
| 1407 | return (_dec_from_triple(sign, '0', 0), |
| 1408 | self._rescale(ideal_exp, context.rounding)) |
| 1409 | if expdiff <= context.prec: |
| 1410 | op1 = _WorkRep(self) |
| 1411 | op2 = _WorkRep(other) |
| 1412 | if op1.exp >= op2.exp: |
| 1413 | op1.int *= 10**(op1.exp - op2.exp) |
| 1414 | else: |
| 1415 | op2.int *= 10**(op2.exp - op1.exp) |
| 1416 | q, r = divmod(op1.int, op2.int) |
| 1417 | if q < 10**context.prec: |
| 1418 | return (_dec_from_triple(sign, str(q), 0), |
| 1419 | _dec_from_triple(self._sign, str(r), ideal_exp)) |
| 1420 | |
| 1421 | # Here the quotient is too large to be representable |
| 1422 | ans = context._raise_error(DivisionImpossible, |
| 1423 | 'quotient too large in //, % or divmod') |
| 1424 | return ans, ans |
| 1425 | |
| 1426 | def __rtruediv__(self, other, context=None): |
| 1427 | """Swaps self/other and returns __truediv__.""" |
no test coverage detected