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

Method _rescale

tools/python-3.11.9-amd64/Lib/_pydecimal.py:2622–2654  ·  view source on GitHub ↗

Rescale self so that the exponent is exp, either by padding with zeros or by truncating digits, using the given rounding mode. Specials are returned without change. This operation is quiet: it raises no flags, and uses no information from the context.

(self, exp, rounding)

Source from the content-addressed store, hash-verified

2620 return self._exp == other._exp
2621
2622 def _rescale(self, exp, rounding):
2623 """Rescale self so that the exponent is exp, either by padding with zeros
2624 or by truncating digits, using the given rounding mode.
2625
2626 Specials are returned without change. This operation is
2627 quiet: it raises no flags, and uses no information from the
2628 context.
2629
2630 exp = exp to scale to (an integer)
2631 rounding = rounding mode
2632 """
2633 if self._is_special:
2634 return Decimal(self)
2635 if not self:
2636 return _dec_from_triple(self._sign, '0', exp)
2637
2638 if self._exp >= exp:
2639 # pad answer with zeros if necessary
2640 return _dec_from_triple(self._sign,
2641 self._int + '0'*(self._exp - exp), exp)
2642
2643 # too many digits; round and lose data. If self.adjusted() <
2644 # exp-1, replace self by 10**(exp-1) before rounding
2645 digits = len(self._int) + self._exp - exp
2646 if digits < 0:
2647 self = _dec_from_triple(self._sign, '1', exp-1)
2648 digits = 0
2649 this_function = self._pick_rounding_function[rounding]
2650 changed = this_function(self, digits)
2651 coeff = self._int[:digits] or '0'
2652 if changed == 1:
2653 coeff = str(int(coeff)+1)
2654 return _dec_from_triple(self._sign, coeff, exp)
2655
2656 def _round(self, places, rounding):
2657 """Round a nonzero, nonspecial Decimal to a fixed number of

Callers 11

__add__Method · 0.95
_divideMethod · 0.95
remainder_nearMethod · 0.95
__round__Method · 0.95
__floor__Method · 0.95
__ceil__Method · 0.95
quantizeMethod · 0.95
_roundMethod · 0.95
to_integral_exactMethod · 0.95
to_integral_valueMethod · 0.95
__format__Method · 0.95

Calls 3

DecimalClass · 0.85
_dec_from_tripleFunction · 0.85
strFunction · 0.85

Tested by

no test coverage detected