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

Function _sqrt_nearest

Lib/_pydecimal.py:5674–5687  ·  view source on GitHub ↗

Closest integer to the square root of the positive integer n. a is an initial approximation to the square root. Any positive integer will do for a, but the closer a is to the square root of n the faster convergence will be.

(n, a)

Source from the content-addressed store, hash-verified

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
5676 an initial approximation to the square root. Any positive integer
5677 will do for a, but the closer a is to the square root of n the
5678 faster convergence will be.
5679
5680 """
5681 if n <= 0 or a <= 0:
5682 raise ValueError("Both arguments to _sqrt_nearest should be positive.")
5683
5684 b=0
5685 while a != b:
5686 b, a = a, a--n//a>>1
5687 return a
5688
5689def _rshift_nearest(x, shift):
5690 """Given an integer x and a nonnegative integer shift, return closest

Callers 1

_ilogFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…