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

Method remainder

Lib/_pydecimal.py:5268–5304  ·  view source on GitHub ↗

Returns the remainder from integer division. The result is the residue of the dividend after the operation of calculating integer division as described for divide-integer, rounded to precision digits if necessary. The sign of the result, if non-zero, is the same as

(self, a, b)

Source from the content-addressed store, hash-verified

5266 return Decimal(10)
5267
5268 def remainder(self, a, b):
5269 """Returns the remainder from integer division.
5270
5271 The result is the residue of the dividend after the operation of
5272 calculating integer division as described for divide-integer, rounded
5273 to precision digits if necessary. The sign of the result, if
5274 non-zero, is the same as that of the original dividend.
5275
5276 This operation will fail under the same conditions as integer division
5277 (that is, if integer division on the same two operands would fail, the
5278 remainder cannot be calculated).
5279
5280 >>> ExtendedContext.remainder(Decimal('2.1'), Decimal('3'))
5281 Decimal('2.1')
5282 >>> ExtendedContext.remainder(Decimal('10'), Decimal('3'))
5283 Decimal('1')
5284 >>> ExtendedContext.remainder(Decimal('-10'), Decimal('3'))
5285 Decimal('-1')
5286 >>> ExtendedContext.remainder(Decimal('10.2'), Decimal('1'))
5287 Decimal('0.2')
5288 >>> ExtendedContext.remainder(Decimal('10'), Decimal('0.3'))
5289 Decimal('0.1')
5290 >>> ExtendedContext.remainder(Decimal('3.6'), Decimal('1.3'))
5291 Decimal('1.0')
5292 >>> ExtendedContext.remainder(22, 6)
5293 Decimal('4')
5294 >>> ExtendedContext.remainder(Decimal(22), 6)
5295 Decimal('4')
5296 >>> ExtendedContext.remainder(22, Decimal(6))
5297 Decimal('4')
5298 """
5299 a = _convert_other(a, raiseit=True)
5300 r = a.__mod__(b, context=self)
5301 if r is NotImplemented:
5302 raise TypeError("Unable to convert %s to Decimal" % b)
5303 else:
5304 return r
5305
5306 def remainder_near(self, a, b):
5307 """Returns to be "a - b * n", where n is the integer nearest the exact

Callers 2

test_remainderMethod · 0.95
testRemainderMethod · 0.80

Calls 2

_convert_otherFunction · 0.85
__mod__Method · 0.45

Tested by 2

test_remainderMethod · 0.76
testRemainderMethod · 0.64