From 022f2bc177cdf02264bf38a9a73fef504f79b82f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Fri, 5 Jun 2020 18:41:24 -0300 Subject: [PATCH] Improve SignedSafeMath docs --- contracts/math/SignedSafeMath.sol | 40 +++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/contracts/math/SignedSafeMath.sol b/contracts/math/SignedSafeMath.sol index f8075df8f..a8f51dc3d 100644 --- a/contracts/math/SignedSafeMath.sol +++ b/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;