Merge pull request #288 from frangio/refactor/math
Move SafeMath and create Math library for assorted operations
This commit is contained in:
24
contracts/math/Math.sol
Normal file
24
contracts/math/Math.sol
Normal file
@ -0,0 +1,24 @@
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
/**
|
||||
* @title Math
|
||||
* @dev Assorted math operations
|
||||
*/
|
||||
|
||||
library Math {
|
||||
function max64(uint64 a, uint64 b) internal constant returns (uint64) {
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
function min64(uint64 a, uint64 b) internal constant returns (uint64) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
function max256(uint256 a, uint256 b) internal constant returns (uint256) {
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
function min256(uint256 a, uint256 b) internal constant returns (uint256) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,8 @@ pragma solidity ^0.4.11;
|
||||
|
||||
|
||||
/**
|
||||
* Math operations with safety checks
|
||||
* @title SafeMath
|
||||
* @dev Math operations with safety checks that throw on error
|
||||
*/
|
||||
library SafeMath {
|
||||
function mul(uint256 a, uint256 b) internal returns (uint256) {
|
||||
@ -28,21 +29,4 @@ library SafeMath {
|
||||
assert(c >= a);
|
||||
return c;
|
||||
}
|
||||
|
||||
function max64(uint64 a, uint64 b) internal constant returns (uint64) {
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
function min64(uint64 a, uint64 b) internal constant returns (uint64) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
function max256(uint256 a, uint256 b) internal constant returns (uint256) {
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
function min256(uint256 a, uint256 b) internal constant returns (uint256) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
|
||||
import '../SafeMath.sol';
|
||||
import '../math/SafeMath.sol';
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -2,7 +2,7 @@ pragma solidity ^0.4.11;
|
||||
|
||||
|
||||
import './ERC20Basic.sol';
|
||||
import '../SafeMath.sol';
|
||||
import '../math/SafeMath.sol';
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
import "../math/Math.sol";
|
||||
import "./StandardToken.sol";
|
||||
import "./LimitedTransferToken.sol";
|
||||
|
||||
@ -121,7 +122,7 @@ contract VestedToken is StandardToken, LimitedTransferToken {
|
||||
|
||||
// Return the minimum of how many vested can transfer and other value
|
||||
// in case there are other limiting transferability factors (default is balanceOf)
|
||||
return SafeMath.min256(vestedTransferable, super.transferableTokens(holder, time));
|
||||
return Math.min256(vestedTransferable, super.transferableTokens(holder, time));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,7 +242,7 @@ contract VestedToken is StandardToken, LimitedTransferToken {
|
||||
date = uint64(now);
|
||||
uint256 grantIndex = grants[holder].length;
|
||||
for (uint256 i = 0; i < grantIndex; i++) {
|
||||
date = SafeMath.max64(grants[holder][i].vesting, date);
|
||||
date = Math.max64(grants[holder][i].vesting, date);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
|
||||
import '../../contracts/SafeMath.sol';
|
||||
import '../../contracts/math/SafeMath.sol';
|
||||
|
||||
|
||||
contract SafeMathMock {
|
||||
|
||||
Reference in New Issue
Block a user