Unverified Commit 9f68c008 by Francisco Giordano Committed by GitHub

Merge pull request #667 from spalladino/feature/655-safemath_docs

Add documentation to safemath functions
parents 4dcf8f5b 49b42e86
...@@ -6,6 +6,10 @@ pragma solidity ^0.4.18; ...@@ -6,6 +6,10 @@ pragma solidity ^0.4.18;
* @dev Math operations with safety checks that throw on error * @dev Math operations with safety checks that throw on error
*/ */
library SafeMath { library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) { function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) { if (a == 0) {
return 0; return 0;
...@@ -15,6 +19,9 @@ library SafeMath { ...@@ -15,6 +19,9 @@ library SafeMath {
return c; return c;
} }
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
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;
...@@ -22,11 +29,17 @@ library SafeMath { ...@@ -22,11 +29,17 @@ library SafeMath {
return c; return c;
} }
/**
* @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
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; return a - b;
} }
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) { function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b; uint256 c = a + b;
assert(c >= a); assert(c >= a);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment