-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMathUtils.sol
32 lines (27 loc) · 955 Bytes
/
MathUtils.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
pragma solidity ^0.4.21;
/* from /~https://github.com/LanguageNetwork/smart-contracts
* @title MathUtils
* @author dongsamb, LangNet.io
*/
library MathUtils {
function ceil(uint256 input, uint256 decimals) pure internal returns (uint256) {
uint256 target = 10 ** decimals;
require(input > target);
return ((input + target - 1) / target) * target;
}
function round(uint256 input, uint256 decimals) pure internal returns (uint256) {
uint256 target = 10 ** decimals;
require(input > target);
return (input / target) * target;
}
function roundOff(uint256 input, uint256 decimals) pure internal returns (uint256) {
uint256 target = 10 ** decimals;
require(input > target);
if ( input % target >= 5 * target / 10 ) {
return ((input + target - 1) / target) * target;
}
else {
return (input / target) * target;
}
}
}