Skip to content

Commit

Permalink
Document rounding behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
MrChico committed Mar 25, 2020
1 parent 784079b commit ce67c0f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/math.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@ contract DSMath {
uint constant WAD = 10 ** 18;
uint constant RAY = 10 ** 27;

//rounds to zero if x*y < WAD / 2
function wmul(uint x, uint y) internal pure returns (uint z) {
z = add(mul(x, y), WAD / 2) / WAD;
}
//rounds to zero if x*y < WAD / 2
function rmul(uint x, uint y) internal pure returns (uint z) {
z = add(mul(x, y), RAY / 2) / RAY;
}
//rounds to zero if x*y < WAD / 2
function wdiv(uint x, uint y) internal pure returns (uint z) {
z = add(mul(x, WAD), y / 2) / y;
}
//rounds to zero if x*y < RAY / 2
function rdiv(uint x, uint y) internal pure returns (uint z) {
z = add(mul(x, RAY), y / 2) / y;
}
Expand Down

0 comments on commit ce67c0f

Please sign in to comment.