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

Method __mod__

Lib/_pydecimal.py:1420–1445  ·  view source on GitHub ↗

self % other

(self, other, context=None)

Source from the content-addressed store, hash-verified

1418 return other.__divmod__(self, context=context)
1419
1420 def __mod__(self, other, context=None):
1421 """
1422 self % other
1423 """
1424 other = _convert_other(other)
1425 if other is NotImplemented:
1426 return other
1427
1428 if context is None:
1429 context = getcontext()
1430
1431 ans = self._check_nans(other, context)
1432 if ans:
1433 return ans
1434
1435 if self._isinfinity():
1436 return context._raise_error(InvalidOperation, 'INF % x')
1437 elif not other:
1438 if self:
1439 return context._raise_error(InvalidOperation, 'x % 0')
1440 else:
1441 return context._raise_error(DivisionUndefined, '0 % 0')
1442
1443 remainder = self._divide(other, context)[1]
1444 remainder = remainder._fix(context)
1445 return remainder
1446
1447 def __rmod__(self, other, context=None):
1448 """Swaps self/other and returns __mod__."""

Callers 2

__rmod__Method · 0.45
remainderMethod · 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