MCPcopy Create free account
hub / github.com/python/cpython / remainder_near

Method remainder_near

Lib/_pydecimal.py:5306–5338  ·  view source on GitHub ↗

Returns to be "a - b * n", where n is the integer nearest the exact value of "x / b" (if two integers are equally near then the even one is chosen). If the result is equal to 0 then its sign will be the sign of a. This operation will fail under the same conditions a

(self, a, b)

Source from the content-addressed store, hash-verified

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
5308 value of "x / b" (if two integers are equally near then the even one
5309 is chosen). If the result is equal to 0 then its sign will be the
5310 sign of a.
5311
5312 This operation will fail under the same conditions as integer division
5313 (that is, if integer division on the same two operands would fail, the
5314 remainder cannot be calculated).
5315
5316 >>> ExtendedContext.remainder_near(Decimal('2.1'), Decimal('3'))
5317 Decimal('-0.9')
5318 >>> ExtendedContext.remainder_near(Decimal('10'), Decimal('6'))
5319 Decimal('-2')
5320 >>> ExtendedContext.remainder_near(Decimal('10'), Decimal('3'))
5321 Decimal('1')
5322 >>> ExtendedContext.remainder_near(Decimal('-10'), Decimal('3'))
5323 Decimal('-1')
5324 >>> ExtendedContext.remainder_near(Decimal('10.2'), Decimal('1'))
5325 Decimal('0.2')
5326 >>> ExtendedContext.remainder_near(Decimal('10'), Decimal('0.3'))
5327 Decimal('0.1')
5328 >>> ExtendedContext.remainder_near(Decimal('3.6'), Decimal('1.3'))
5329 Decimal('-0.3')
5330 >>> ExtendedContext.remainder_near(3, 11)
5331 Decimal('3')
5332 >>> ExtendedContext.remainder_near(Decimal(3), 11)
5333 Decimal('3')
5334 >>> ExtendedContext.remainder_near(3, Decimal(11))
5335 Decimal('3')
5336 """
5337 a = _convert_other(a, raiseit=True)
5338 return a.remainder_near(b, context=self)
5339
5340 def rotate(self, a, b):
5341 """Returns a rotated copy of a, b times.

Callers 1

test_remainder_nearMethod · 0.95

Calls 2

_convert_otherFunction · 0.85
remainder_nearMethod · 0.45

Tested by 1

test_remainder_nearMethod · 0.76