MCPcopy Index your code
hub / github.com/python/cpython / __divmod__

Method __divmod__

Lib/_pydecimal.py:1377–1411  ·  view source on GitHub ↗

Return (self // other, self % other)

(self, other, context=None)

Source from the content-addressed store, hash-verified

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__."""

Callers 2

__rdivmod__Method · 0.45
divmodMethod · 0.45

Calls 7

_check_nansMethod · 0.95
_isinfinityMethod · 0.95
_divideMethod · 0.95
_convert_otherFunction · 0.85
getcontextFunction · 0.85
_raise_errorMethod · 0.80
_fixMethod · 0.80

Tested by

no test coverage detected