Improve SignedSafeMath docs

pull/2273/head
Nicolás Venturo 5 years ago
parent ccf79ee483
commit 022f2bc177
  1. 40
      contracts/math/SignedSafeMath.sol

@ -9,8 +9,15 @@ pragma solidity ^0.6.0;
library SignedSafeMath {
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) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
@ -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) {
require(b != 0, "SignedSafeMath: division by zero");
@ -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) {
int256 c = a - b;
@ -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) {
int256 c = a + b;

Loading…
Cancel
Save