MCPcopy Index your code
hub / github.com/python/cpython / normalize

Method normalize

Lib/_pydecimal.py:2476–2499  ·  view source on GitHub ↗

Normalize- strip trailing 0s, change anything equal to 0 to 0e0

(self, context=None)

Source from the content-addressed store, hash-verified

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.

Callers 9

test_none_argsMethod · 0.95
_expand_langFunction · 0.45
map_table_b2Function · 0.45
normalizeMethod · 0.45
optimizeFunction · 0.45
checkFunction · 0.45
map_table_b2Function · 0.45
is_installedFunction · 0.45
is_standaloneFunction · 0.45

Calls 6

_check_nansMethod · 0.95
_fixMethod · 0.95
getcontextFunction · 0.85
_dec_from_tripleFunction · 0.85
_isinfinityMethod · 0.80
EtopMethod · 0.80

Tested by 1

test_none_argsMethod · 0.76