MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _divide

Method _divide

tools/python-3.11.9-amd64/Lib/_pydecimal.py:1393–1424  ·  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

1391 return ans._fix(context)
1392
1393 def _divide(self, other, context):
1394 """Return (self // other, self % other), to context.prec precision.
1395
1396 Assumes that neither self nor other is a NaN, that self is not
1397 infinite and that other is nonzero.
1398 """
1399 sign = self._sign ^ other._sign
1400 if other._isinfinity():
1401 ideal_exp = self._exp
1402 else:
1403 ideal_exp = min(self._exp, other._exp)
1404
1405 expdiff = self.adjusted() - other.adjusted()
1406 if not self or other._isinfinity() or expdiff <= -2:
1407 return (_dec_from_triple(sign, '0', 0),
1408 self._rescale(ideal_exp, context.rounding))
1409 if expdiff <= context.prec:
1410 op1 = _WorkRep(self)
1411 op2 = _WorkRep(other)
1412 if op1.exp >= op2.exp:
1413 op1.int *= 10**(op1.exp - op2.exp)
1414 else:
1415 op2.int *= 10**(op2.exp - op1.exp)
1416 q, r = divmod(op1.int, op2.int)
1417 if q < 10**context.prec:
1418 return (_dec_from_triple(sign, str(q), 0),
1419 _dec_from_triple(self._sign, str(r), ideal_exp))
1420
1421 # Here the quotient is too large to be representable
1422 ans = context._raise_error(DivisionImpossible,
1423 'quotient too large in //, % or divmod')
1424 return ans, ans
1425
1426 def __rtruediv__(self, other, context=None):
1427 """Swaps self/other and returns __truediv__."""

Callers 3

__divmod__Method · 0.95
__mod__Method · 0.95
__floordiv__Method · 0.95

Calls 8

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

Tested by

no test coverage detected