MCPcopy Index your code
hub / github.com/RustPython/RustPython / normalize

Method normalize

Lib/_pydecimal.py:2473–2496  ·  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

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

Callers 5

test_none_argsMethod · 0.95
_expand_langFunction · 0.45
map_table_b2Function · 0.45
normalizeMethod · 0.45

Calls 7

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

Tested by 1

test_none_argsMethod · 0.76