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

Method _divide

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

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

Callers 3

__divmod__Method · 0.95
__mod__Method · 0.95
__floordiv__Method · 0.95

Calls 9

adjustedMethod · 0.95
_rescaleMethod · 0.95
minFunction · 0.85
_dec_from_tripleFunction · 0.85
_WorkRepClass · 0.85
strFunction · 0.85
_isinfinityMethod · 0.80
_raise_errorMethod · 0.80
divmodFunction · 0.50

Tested by

no test coverage detected