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. exp =
(self, exp, rounding)
| 2575 | return self._exp == other._exp |
| 2576 | |
| 2577 | def _rescale(self, exp, rounding): |
| 2578 | """Rescale self so that the exponent is exp, either by padding with zeros |
| 2579 | or by truncating digits, using the given rounding mode. |
| 2580 | |
| 2581 | Specials are returned without change. This operation is |
| 2582 | quiet: it raises no flags, and uses no information from the |
| 2583 | context. |
| 2584 | |
| 2585 | exp = exp to scale to (an integer) |
| 2586 | rounding = rounding mode |
| 2587 | """ |
| 2588 | if self._is_special: |
| 2589 | return Decimal(self) |
| 2590 | if not self: |
| 2591 | return _dec_from_triple(self._sign, '0', exp) |
| 2592 | |
| 2593 | if self._exp >= exp: |
| 2594 | # pad answer with zeros if necessary |
| 2595 | return _dec_from_triple(self._sign, |
| 2596 | self._int + '0'*(self._exp - exp), exp) |
| 2597 | |
| 2598 | # too many digits; round and lose data. If self.adjusted() < |
| 2599 | # exp-1, replace self by 10**(exp-1) before rounding |
| 2600 | digits = len(self._int) + self._exp - exp |
| 2601 | if digits < 0: |
| 2602 | self = _dec_from_triple(self._sign, '1', exp-1) |
| 2603 | digits = 0 |
| 2604 | this_function = self._pick_rounding_function[rounding] |
| 2605 | changed = this_function(self, digits) |
| 2606 | coeff = self._int[:digits] or '0' |
| 2607 | if changed == 1: |
| 2608 | coeff = str(int(coeff)+1) |
| 2609 | return _dec_from_triple(self._sign, coeff, exp) |
| 2610 | |
| 2611 | def _round(self, places, rounding): |
| 2612 | """Round a nonzero, nonspecial Decimal to a fixed number of |