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

Function _decimal_lshift_exact

Lib/_pydecimal.py:5653–5672  ·  view source on GitHub ↗

Given integers n and e, return n * 10**e if it's an integer, else None. The computation is designed to avoid computing large powers of 10 unnecessarily. >>> _decimal_lshift_exact(3, 4) 30000 >>> _decimal_lshift_exact(300, -999999999) # returns None

(n, e)

Source from the content-addressed store, hash-verified

5651_nbits = int.bit_length
5652
5653def _decimal_lshift_exact(n, e):
5654 """ Given integers n and e, return n * 10**e if it's an integer, else None.
5655
5656 The computation is designed to avoid computing large powers of 10
5657 unnecessarily.
5658
5659 >>> _decimal_lshift_exact(3, 4)
5660 30000
5661 >>> _decimal_lshift_exact(300, -999999999) # returns None
5662
5663 """
5664 if n == 0:
5665 return 0
5666 elif e >= 0:
5667 return n * 10**e
5668 else:
5669 # val_n = largest power of 10 dividing n.
5670 str_n = str(abs(n))
5671 val_n = len(str_n) - len(str_n.rstrip('0'))
5672 return None if val_n < -e else n // 10**-e
5673
5674def _sqrt_nearest(n, a):
5675 """Closest integer to the square root of the positive integer n. a is

Callers 1

_power_exactMethod · 0.85

Calls 3

strFunction · 0.85
absFunction · 0.85
rstripMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…