Return (self // other, self % other)
(self, other, context=None)
| 1431 | return other.__truediv__(self, context=context) |
| 1432 | |
| 1433 | def __divmod__(self, other, context=None): |
| 1434 | """ |
| 1435 | Return (self // other, self % other) |
| 1436 | """ |
| 1437 | other = _convert_other(other) |
| 1438 | if other is NotImplemented: |
| 1439 | return other |
| 1440 | |
| 1441 | if context is None: |
| 1442 | context = getcontext() |
| 1443 | |
| 1444 | ans = self._check_nans(other, context) |
| 1445 | if ans: |
| 1446 | return (ans, ans) |
| 1447 | |
| 1448 | sign = self._sign ^ other._sign |
| 1449 | if self._isinfinity(): |
| 1450 | if other._isinfinity(): |
| 1451 | ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)') |
| 1452 | return ans, ans |
| 1453 | else: |
| 1454 | return (_SignedInfinity[sign], |
| 1455 | context._raise_error(InvalidOperation, 'INF % x')) |
| 1456 | |
| 1457 | if not other: |
| 1458 | if not self: |
| 1459 | ans = context._raise_error(DivisionUndefined, 'divmod(0, 0)') |
| 1460 | return ans, ans |
| 1461 | else: |
| 1462 | return (context._raise_error(DivisionByZero, 'x // 0', sign), |
| 1463 | context._raise_error(InvalidOperation, 'x % 0')) |
| 1464 | |
| 1465 | quotient, remainder = self._divide(other, context) |
| 1466 | remainder = remainder._fix(context) |
| 1467 | return quotient, remainder |
| 1468 | |
| 1469 | def __rdivmod__(self, other, context=None): |
| 1470 | """Swaps self/other and returns __divmod__.""" |
no test coverage detected