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

Method _divide

Lib/_pydecimal.py:1337–1368  ·  view source on GitHub ↗

Return (self // other, self % other), to context.prec precision. Assumes that neither self nor other is a NaN, that self is not infinite and that other is nonzero.

(self, other, context)

Source from the content-addressed store, hash-verified

1335 return ans._fix(context)
1336
1337 def _divide(self, other, context):
1338 """Return (self // other, self % other), to context.prec precision.
1339
1340 Assumes that neither self nor other is a NaN, that self is not
1341 infinite and that other is nonzero.
1342 """
1343 sign = self._sign ^ other._sign
1344 if other._isinfinity():
1345 ideal_exp = self._exp
1346 else:
1347 ideal_exp = min(self._exp, other._exp)
1348
1349 expdiff = self.adjusted() - other.adjusted()
1350 if not self or other._isinfinity() or expdiff <= -2:
1351 return (_dec_from_triple(sign, '0', 0),
1352 self._rescale(ideal_exp, context.rounding))
1353 if expdiff <= context.prec:
1354 op1 = _WorkRep(self)
1355 op2 = _WorkRep(other)
1356 if op1.exp >= op2.exp:
1357 op1.int *= 10**(op1.exp - op2.exp)
1358 else:
1359 op2.int *= 10**(op2.exp - op1.exp)
1360 q, r = divmod(op1.int, op2.int)
1361 if q < 10**context.prec:
1362 return (_dec_from_triple(sign, str(q), 0),
1363 _dec_from_triple(self._sign, str(r), ideal_exp))
1364
1365 # Here the quotient is too large to be representable
1366 ans = context._raise_error(DivisionImpossible,
1367 'quotient too large in //, % or divmod')
1368 return ans, ans
1369
1370 def __rtruediv__(self, other, context=None):
1371 """Swaps self/other and returns __truediv__."""

Callers 3

__divmod__Method · 0.95
__mod__Method · 0.95
__floordiv__Method · 0.95

Calls 7

adjustedMethod · 0.95
_rescaleMethod · 0.95
_dec_from_tripleFunction · 0.85
_WorkRepClass · 0.85
strFunction · 0.85
_isinfinityMethod · 0.80
_raise_errorMethod · 0.80

Tested by

no test coverage detected