From 88a22fc44498a8b2d153e236d23215dc6a5d1145 Mon Sep 17 00:00:00 2001 From: michael spengler <43786652+michael-spengler@users.noreply.github.com> Date: Tue, 22 Mar 2022 16:17:28 +0100 Subject: [PATCH] Update Math.sol --- contracts/utils/math/Math.sol | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/contracts/utils/math/Math.sol b/contracts/utils/math/Math.sol index 291d257b0d8..9fa1b9bc2bc 100644 --- a/contracts/utils/math/Math.sol +++ b/contracts/utils/math/Math.sol @@ -40,4 +40,18 @@ library Math { // (a + b - 1) / b can overflow on addition, so we distribute. return a / b + (a % b == 0 ? 0 : 1); } + + /** + * @dev Returns the square root of a number. + */ + function sqrt(uint256 x) public pure returns (uint256 y) { + uint256 z = (x + 1) / 2; + y = x; + while (z < y) { + y = z; + z = (x / z + z) / 2; + } + return y; + } + }