Skip to content

Commit d5a7536

Browse files
authored
Merge pull request #288 from frangio/refactor/math
Move SafeMath and create Math library for assorted operations
2 parents e748c3e + 421ed4f commit d5a7536

File tree

6 files changed

+32
-23
lines changed

6 files changed

+32
-23
lines changed

contracts/math/Math.sol

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
pragma solidity ^0.4.11;
2+
3+
/**
4+
* @title Math
5+
* @dev Assorted math operations
6+
*/
7+
8+
library Math {
9+
function max64(uint64 a, uint64 b) internal constant returns (uint64) {
10+
return a >= b ? a : b;
11+
}
12+
13+
function min64(uint64 a, uint64 b) internal constant returns (uint64) {
14+
return a < b ? a : b;
15+
}
16+
17+
function max256(uint256 a, uint256 b) internal constant returns (uint256) {
18+
return a >= b ? a : b;
19+
}
20+
21+
function min256(uint256 a, uint256 b) internal constant returns (uint256) {
22+
return a < b ? a : b;
23+
}
24+
}

contracts/SafeMath.sol renamed to contracts/math/SafeMath.sol

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ pragma solidity ^0.4.11;
22

33

44
/**
5-
* Math operations with safety checks
5+
* @title SafeMath
6+
* @dev Math operations with safety checks that throw on error
67
*/
78
library SafeMath {
89
function mul(uint256 a, uint256 b) internal returns (uint256) {
@@ -28,21 +29,4 @@ library SafeMath {
2829
assert(c >= a);
2930
return c;
3031
}
31-
32-
function max64(uint64 a, uint64 b) internal constant returns (uint64) {
33-
return a >= b ? a : b;
34-
}
35-
36-
function min64(uint64 a, uint64 b) internal constant returns (uint64) {
37-
return a < b ? a : b;
38-
}
39-
40-
function max256(uint256 a, uint256 b) internal constant returns (uint256) {
41-
return a >= b ? a : b;
42-
}
43-
44-
function min256(uint256 a, uint256 b) internal constant returns (uint256) {
45-
return a < b ? a : b;
46-
}
47-
4832
}

contracts/payment/PullPayment.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pragma solidity ^0.4.11;
22

33

4-
import '../SafeMath.sol';
4+
import '../math/SafeMath.sol';
55

66

77
/**

contracts/token/BasicToken.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pragma solidity ^0.4.11;
22

33

44
import './ERC20Basic.sol';
5-
import '../SafeMath.sol';
5+
import '../math/SafeMath.sol';
66

77

88
/**

contracts/token/VestedToken.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pragma solidity ^0.4.11;
22

3+
import "../math/Math.sol";
34
import "./StandardToken.sol";
45
import "./LimitedTransferToken.sol";
56

@@ -121,7 +122,7 @@ contract VestedToken is StandardToken, LimitedTransferToken {
121122

122123
// Return the minimum of how many vested can transfer and other value
123124
// in case there are other limiting transferability factors (default is balanceOf)
124-
return SafeMath.min256(vestedTransferable, super.transferableTokens(holder, time));
125+
return Math.min256(vestedTransferable, super.transferableTokens(holder, time));
125126
}
126127

127128
/**
@@ -241,7 +242,7 @@ contract VestedToken is StandardToken, LimitedTransferToken {
241242
date = uint64(now);
242243
uint256 grantIndex = grants[holder].length;
243244
for (uint256 i = 0; i < grantIndex; i++) {
244-
date = SafeMath.max64(grants[holder][i].vesting, date);
245+
date = Math.max64(grants[holder][i].vesting, date);
245246
}
246247
}
247248
}

test/helpers/SafeMathMock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pragma solidity ^0.4.11;
22

33

4-
import '../../contracts/SafeMath.sol';
4+
import '../../contracts/math/SafeMath.sol';
55

66

77
contract SafeMathMock {

0 commit comments

Comments
 (0)