Commit d5a75362 by Manuel Aráoz Committed by GitHub

Merge pull request #288 from frangio/refactor/math

Move SafeMath and create Math library for assorted operations
parents e748c3ea 421ed4f8
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;
}
}
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';
/**
......
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);
}
}
}
pragma solidity ^0.4.11;
import '../../contracts/SafeMath.sol';
import '../../contracts/math/SafeMath.sol';
contract SafeMathMock {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment