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
a3e312d1
Unverified
Commit
a3e312d1
authored
Oct 16, 2018
by
Nicolás Venturo
Committed by
GitHub
Oct 16, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Math.sol docstrings. (#1423)
parent
3341dd88
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
0 deletions
+11
-0
Math.sol
contracts/math/Math.sol
+11
-0
No files found.
contracts/math/Math.sol
View file @
a3e312d1
...
@@ -5,14 +5,25 @@ pragma solidity ^0.4.24;
...
@@ -5,14 +5,25 @@ pragma solidity ^0.4.24;
* @dev Assorted math operations
* @dev Assorted math operations
*/
*/
library Math {
library Math {
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
return a >= b ? a : b;
}
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
return a < b ? a : b;
}
}
/**
* @dev Calculates the average of two numbers. Since these are integers,
* averages of an even and odd number cannot be represented, and will be
* rounded down.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow, so we distribute
// (a + b) / 2 can overflow, so we distribute
return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
...
...
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