MCPcopy Index your code
hub / github.com/RustPython/RustPython / remainder

Method remainder

Lib/_pydecimal.py:5265–5301  ·  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

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

Callers 3

test_remainderMethod · 0.95
testRemainderMethod · 0.80
templateFunction · 0.80

Calls 2

_convert_otherFunction · 0.85
__mod__Method · 0.45

Tested by 2

test_remainderMethod · 0.76
testRemainderMethod · 0.64