MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _sqrt_nearest

Function _sqrt_nearest

tools/python-3.11.9-amd64/Lib/_pydecimal.py:5707–5720  ·  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

5705 return None if val_n < -e else n // 10**-e
5706
5707def _sqrt_nearest(n, a):
5708 """Closest integer to the square root of the positive integer n. a is
5709 an initial approximation to the square root. Any positive integer
5710 will do for a, but the closer a is to the square root of n the
5711 faster convergence will be.
5712
5713 """
5714 if n <= 0 or a <= 0:
5715 raise ValueError("Both arguments to _sqrt_nearest should be positive.")
5716
5717 b=0
5718 while a != b:
5719 b, a = a, a--n//a>>1
5720 return a
5721
5722def _rshift_nearest(x, shift):
5723 """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