Normalize- strip trailing 0s, change anything equal to 0 to 0e0
(self, context=None)
| 2474 | return other.__pow__(self, modulo, context=context) |
| 2475 | |
| 2476 | def normalize(self, context=None): |
| 2477 | """Normalize- strip trailing 0s, change anything equal to 0 to 0e0""" |
| 2478 | |
| 2479 | if context is None: |
| 2480 | context = getcontext() |
| 2481 | |
| 2482 | if self._is_special: |
| 2483 | ans = self._check_nans(context=context) |
| 2484 | if ans: |
| 2485 | return ans |
| 2486 | |
| 2487 | dup = self._fix(context) |
| 2488 | if dup._isinfinity(): |
| 2489 | return dup |
| 2490 | |
| 2491 | if not dup: |
| 2492 | return _dec_from_triple(dup._sign, '0', 0) |
| 2493 | exp_max = [context.Emax, context.Etop()][context.clamp] |
| 2494 | end = len(dup._int) |
| 2495 | exp = dup._exp |
| 2496 | while dup._int[end-1] == '0' and exp < exp_max: |
| 2497 | exp += 1 |
| 2498 | end -= 1 |
| 2499 | return _dec_from_triple(dup._sign, dup._int[:end], exp) |
| 2500 | |
| 2501 | def quantize(self, exp, rounding=None, context=None): |
| 2502 | """Quantize self so its exponent is the same as that of exp. |