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