uniswap-v2-contracts/src/libraries/Math.sol
Uncle Fatso cfd9857dc0
initial commit
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
2025-05-11 16:04:09 +03:00

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;
}
}
}