49 lines
1.2 KiB
Solidity
49 lines
1.2 KiB
Solidity
/*
|
|
|
|
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;
|
|
uint256 constant ONE2 = 10**36;
|
|
|
|
function mulFloor(uint256 target, uint256 d) internal pure returns (uint256) {
|
|
return target.mul(d) / (10**18);
|
|
}
|
|
|
|
function mulCeil(uint256 target, uint256 d) internal pure returns (uint256) {
|
|
return target.mul(d).divCeil(10**18);
|
|
}
|
|
|
|
function divFloor(uint256 target, uint256 d) internal pure returns (uint256) {
|
|
return target.mul(10**18).div(d);
|
|
}
|
|
|
|
function divCeil(uint256 target, uint256 d) internal pure returns (uint256) {
|
|
return target.mul(10**18).divCeil(d);
|
|
}
|
|
|
|
function reciprocalFloor(uint256 target) internal pure returns (uint256) {
|
|
return uint256(10**36).div(target);
|
|
}
|
|
|
|
function reciprocalCeil(uint256 target) internal pure returns (uint256) {
|
|
return uint256(10**36).divCeil(target);
|
|
}
|
|
}
|