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)
| 1335 | return ans._fix(context) |
| 1336 | |
| 1337 | def _divide(self, other, context): |
| 1338 | """Return (self // other, self % other), to context.prec precision. |
| 1339 | |
| 1340 | Assumes that neither self nor other is a NaN, that self is not |
| 1341 | infinite and that other is nonzero. |
| 1342 | """ |
| 1343 | sign = self._sign ^ other._sign |
| 1344 | if other._isinfinity(): |
| 1345 | ideal_exp = self._exp |
| 1346 | else: |
| 1347 | ideal_exp = min(self._exp, other._exp) |
| 1348 | |
| 1349 | expdiff = self.adjusted() - other.adjusted() |
| 1350 | if not self or other._isinfinity() or expdiff <= -2: |
| 1351 | return (_dec_from_triple(sign, '0', 0), |
| 1352 | self._rescale(ideal_exp, context.rounding)) |
| 1353 | if expdiff <= context.prec: |
| 1354 | op1 = _WorkRep(self) |
| 1355 | op2 = _WorkRep(other) |
| 1356 | if op1.exp >= op2.exp: |
| 1357 | op1.int *= 10**(op1.exp - op2.exp) |
| 1358 | else: |
| 1359 | op2.int *= 10**(op2.exp - op1.exp) |
| 1360 | q, r = divmod(op1.int, op2.int) |
| 1361 | if q < 10**context.prec: |
| 1362 | return (_dec_from_triple(sign, str(q), 0), |
| 1363 | _dec_from_triple(self._sign, str(r), ideal_exp)) |
| 1364 | |
| 1365 | # Here the quotient is too large to be representable |
| 1366 | ans = context._raise_error(DivisionImpossible, |
| 1367 | 'quotient too large in //, % or divmod') |
| 1368 | return ans, ans |
| 1369 | |
| 1370 | def __rtruediv__(self, other, context=None): |
| 1371 | """Swaps self/other and returns __truediv__.""" |
no test coverage detected