Return (self // other, self % other)
(self, other, context=None)
| 1375 | return other.__truediv__(self, context=context) |
| 1376 | |
| 1377 | def __divmod__(self, other, context=None): |
| 1378 | """ |
| 1379 | Return (self // other, self % other) |
| 1380 | """ |
| 1381 | other = _convert_other(other) |
| 1382 | if other is NotImplemented: |
| 1383 | return other |
| 1384 | |
| 1385 | if context is None: |
| 1386 | context = getcontext() |
| 1387 | |
| 1388 | ans = self._check_nans(other, context) |
| 1389 | if ans: |
| 1390 | return (ans, ans) |
| 1391 | |
| 1392 | sign = self._sign ^ other._sign |
| 1393 | if self._isinfinity(): |
| 1394 | if other._isinfinity(): |
| 1395 | ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)') |
| 1396 | return ans, ans |
| 1397 | else: |
| 1398 | return (_SignedInfinity[sign], |
| 1399 | context._raise_error(InvalidOperation, 'INF % x')) |
| 1400 | |
| 1401 | if not other: |
| 1402 | if not self: |
| 1403 | ans = context._raise_error(DivisionUndefined, 'divmod(0, 0)') |
| 1404 | return ans, ans |
| 1405 | else: |
| 1406 | return (context._raise_error(DivisionByZero, 'x // 0', sign), |
| 1407 | context._raise_error(InvalidOperation, 'x % 0')) |
| 1408 | |
| 1409 | quotient, remainder = self._divide(other, context) |
| 1410 | remainder = remainder._fix(context) |
| 1411 | return quotient, remainder |
| 1412 | |
| 1413 | def __rdivmod__(self, other, context=None): |
| 1414 | """Swaps self/other and returns __divmod__.""" |
no test coverage detected