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

Function _decimal_lshift_exact

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

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

Callers 1

_power_exactMethod · 0.85

Calls 4

strFunction · 0.85
lenFunction · 0.85
absFunction · 0.70
rstripMethod · 0.45

Tested by

no test coverage detected