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
022f2bc1
Commit
022f2bc1
authored
Jun 05, 2020
by
Nicolás Venturo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve SignedSafeMath docs
parent
ccf79ee4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
5 deletions
+35
-5
SignedSafeMath.sol
contracts/math/SignedSafeMath.sol
+35
-5
No files found.
contracts/math/SignedSafeMath.sol
View file @
022f2bc1
...
@@ -9,8 +9,15 @@ pragma solidity ^0.6.0;
...
@@ -9,8 +9,15 @@ pragma solidity ^0.6.0;
library SignedSafeMath {
library SignedSafeMath {
int256 constant private _INT256_MIN = -2**255;
int256 constant private _INT256_MIN = -2**255;
/**
/**
* @dev Multiplies two signed integers, reverts on overflow.
* @dev Returns the multiplication of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
*/
function mul(int256 a, int256 b) internal pure returns (int256) {
function mul(int256 a, int256 b) internal pure returns (int256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
...
@@ -29,7 +36,16 @@ library SignedSafeMath {
...
@@ -29,7 +36,16 @@ library SignedSafeMath {
}
}
/**
/**
* @dev Integer division of two signed integers truncating the quotient, reverts on division by zero.
* @dev Returns the integer division of two signed integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
*/
function div(int256 a, int256 b) internal pure returns (int256) {
function div(int256 a, int256 b) internal pure returns (int256) {
require(b != 0, "SignedSafeMath: division by zero");
require(b != 0, "SignedSafeMath: division by zero");
...
@@ -41,7 +57,14 @@ library SignedSafeMath {
...
@@ -41,7 +57,14 @@ library SignedSafeMath {
}
}
/**
/**
* @dev Subtracts two signed integers, reverts on overflow.
* @dev Returns the subtraction of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
*/
function sub(int256 a, int256 b) internal pure returns (int256) {
function sub(int256 a, int256 b) internal pure returns (int256) {
int256 c = a - b;
int256 c = a - b;
...
@@ -51,7 +74,14 @@ library SignedSafeMath {
...
@@ -51,7 +74,14 @@ library SignedSafeMath {
}
}
/**
/**
* @dev Adds two signed integers, reverts on overflow.
* @dev Returns the addition of two signed integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
*/
function add(int256 a, int256 b) internal pure returns (int256) {
function add(int256 a, int256 b) internal pure returns (int256) {
int256 c = a + b;
int256 c = a + b;
...
...
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