23 lines
608 B
Solidity
23 lines
608 B
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity =0.8.20;
|
|
|
|
library UniswapV2Math {
|
|
function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
|
|
z = x < y ? x : y;
|
|
}
|
|
|
|
// babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
|
|
function sqrt(uint256 y) internal pure returns (uint256 z) {
|
|
if (y > 3) {
|
|
z = y;
|
|
uint256 x = y / 2 + 1;
|
|
while (x < z) {
|
|
z = x;
|
|
x = (y / x + x) / 2;
|
|
}
|
|
} else if (y != 0) {
|
|
z = 1;
|
|
}
|
|
}
|
|
}
|