https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
Example
To calculate √S, where S = 125348, to six significant figures, use the rough estimation method above to get
Therefore, √125348 ≈ 354.045.
Uniswap 中用法
// babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
function sqrt(uint y) internal pure returns (uint z) {
if (y > 3) {
z = y;
uint x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}