first commit
This commit is contained in:
35
contracts/lib/DecimalMath.sol
Normal file
35
contracts/lib/DecimalMath.sol
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {SafeMath} from "./SafeMath.sol";
|
||||
|
||||
/**
|
||||
* @title DecimalMath
|
||||
* @author DODO Breeder
|
||||
*
|
||||
* @notice Functions for fixed point number with 18 decimals
|
||||
*/
|
||||
library DecimalMath {
|
||||
using SafeMath for uint256;
|
||||
|
||||
uint256 constant ONE = 10**18;
|
||||
|
||||
function mul(uint256 target, uint256 d) internal pure returns (uint256) {
|
||||
return target.mul(d) / ONE;
|
||||
}
|
||||
|
||||
function divFloor(uint256 target, uint256 d) internal pure returns (uint256) {
|
||||
return target.mul(ONE).div(d);
|
||||
}
|
||||
|
||||
function divCeil(uint256 target, uint256 d) internal pure returns (uint256) {
|
||||
return target.mul(ONE).divCeil(d);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user