Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
e819416d
Unverified
Commit
e819416d
authored
Aug 08, 2018
by
Nicolás Venturo
Committed by
GitHub
Aug 08, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SafeMath is now more consistent with itself. (#1168)
parent
eca5bf91
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
7 deletions
+12
-7
SafeMath.sol
contracts/math/SafeMath.sol
+12
-7
No files found.
contracts/math/SafeMath.sol
View file @
e819416d
...
@@ -10,7 +10,7 @@ library SafeMath {
...
@@ -10,7 +10,7 @@ library SafeMath {
/**
/**
* @dev Multiplies two numbers, throws on overflow.
* @dev Multiplies two numbers, throws on overflow.
*/
*/
function mul(uint256 _a, uint256 _b) internal pure returns (uint256
c
) {
function mul(uint256 _a, uint256 _b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than asserting 'a' not being zero, but the
// Gas optimization: this is cheaper than asserting 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
...
@@ -18,8 +18,9 @@ library SafeMath {
...
@@ -18,8 +18,9 @@ library SafeMath {
return 0;
return 0;
}
}
c = _a * _b;
uint256
c = _a * _b;
assert(c / _a == _b);
assert(c / _a == _b);
return c;
return c;
}
}
...
@@ -28,9 +29,10 @@ library SafeMath {
...
@@ -28,9 +29,10 @@ library SafeMath {
*/
*/
function div(uint256 _a, uint256 _b) internal pure returns (uint256) {
function div(uint256 _a, uint256 _b) internal pure returns (uint256) {
// assert(_b > 0); // Solidity automatically throws when dividing by 0
// assert(_b > 0); // Solidity automatically throws when dividing by 0
//
uint256 c = _a / _b;
uint256 c = _a / _b;
// assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold
// assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold
return _a / _b;
return c;
}
}
/**
/**
...
@@ -38,15 +40,18 @@ library SafeMath {
...
@@ -38,15 +40,18 @@ library SafeMath {
*/
*/
function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
assert(_b <= _a);
assert(_b <= _a);
return _a - _b;
uint256 c = _a - _b;
return c;
}
}
/**
/**
* @dev Adds two numbers, throws on overflow.
* @dev Adds two numbers, throws on overflow.
*/
*/
function add(uint256 _a, uint256 _b) internal pure returns (uint256
c
) {
function add(uint256 _a, uint256 _b) internal pure returns (uint256) {
c = _a + _b;
uint256
c = _a + _b;
assert(c >= _a);
assert(c >= _a);
return c;
return c;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment