mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
23 lines
576 B
Solidity
23 lines
576 B
Solidity
|
pragma solidity ^0.6.0;
|
||
|
|
||
|
contract DSMath {
|
||
|
|
||
|
function add(uint x, uint y) internal pure returns (uint z) {
|
||
|
require((z = x + y) >= x, "math-not-safe");
|
||
|
}
|
||
|
|
||
|
function mul(uint x, uint y) internal pure returns (uint z) {
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
function wdiv(uint x, uint y) internal pure returns (uint z) {
|
||
|
z = add(mul(x, WAD), y / 2) / y;
|
||
|
}
|
||
|
|
||
|
}
|