From d9a2bf5671e5c1a27f194e960ac4961f95e7d815 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Sat, 2 May 2020 20:03:39 +0530 Subject: [PATCH] updated math.sol --- contracts/common/math.sol | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/contracts/common/math.sol b/contracts/common/math.sol index 79b1ff9..6758549 100644 --- a/contracts/common/math.sol +++ b/contracts/common/math.sol @@ -1,6 +1,8 @@ pragma solidity ^0.6.0; contract DSMath { + uint constant WAD = 10 ** 18; + uint constant RAY = 10 ** 27; function add(uint x, uint y) internal pure returns (uint z) { require((z = x + y) >= x, "math-not-safe"); @@ -10,7 +12,6 @@ contract DSMath { require(y == 0 || (z = x * y) / y == x, "math-not-safe"); } - uint constant WAD = 10 ** 18; function wmul(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, y), WAD / 2) / WAD; @@ -20,4 +21,12 @@ contract DSMath { z = add(mul(x, WAD), y / 2) / y; } + function rdiv(uint x, uint y) internal pure returns (uint z) { + z = add(mul(x, RAY), y / 2) / y; + } + + function rmul(uint x, uint y) internal pure returns (uint z) { + z = add(mul(x, y), RAY / 2) / RAY; + } + } \ No newline at end of file