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)
| 5672 | return None if val_n < -e else n // 10**-e |
| 5673 | |
| 5674 | def _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 | |
| 5689 | def _rshift_nearest(x, shift): |
| 5690 | """Given an integer x and a nonnegative integer shift, return closest |
no outgoing calls
no test coverage detected
searching dependent graphs…