* Now compiling in a separate directory using truffle 5. * Ported to 0.5.1, now compiling using 0.5.1. * test now also compiles using the truffle 5 hack. * Downgraded to 0.5.0. * Sorted scripts. * Cleaned up the compile script a bit.
32 lines
826 B
Solidity
32 lines
826 B
Solidity
pragma solidity ^0.5.0;
|
|
|
|
/**
|
|
* @title Math
|
|
* @dev Assorted math operations
|
|
*/
|
|
library Math {
|
|
/**
|
|
* @dev Returns the largest of two numbers.
|
|
*/
|
|
function max(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
return a >= b ? a : b;
|
|
}
|
|
|
|
/**
|
|
* @dev Returns the smallest of two numbers.
|
|
*/
|
|
function min(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
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) {
|
|
// (a + b) / 2 can overflow, so we distribute
|
|
return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
|
|
}
|
|
}
|