Skip to main content

Math

Git Source

Wrappers over Solidity's arithmetic operations with added overflow checks. Adapted from OpenZeppelin's SafeMath library.

Functions

abs

Returns the absolute value of a signed integer.

function abs(int256 a) internal pure returns (uint256 result);

add

Returns the addition of two unsigned integers of 256 bits, reverting on overflow.

function add(uint256 a, uint256 b) internal pure returns (uint256);

add

Returns the addition of two signed integers, reverting on overflow.

function add(int256 a, int256 b) internal pure returns (int256);

sub

Returns the subtraction of two unsigned integers of 256 bits, reverting on overflow.

function sub(uint256 a, uint256 b) internal pure returns (uint256);

sub

Returns the subtraction of two signed integers, reverting on overflow.

function sub(int256 a, int256 b) internal pure returns (int256);

max

Returns the largest of two numbers of 256 bits.

function max(uint256 a, uint256 b) internal pure returns (uint256 result);

min

Returns the smallest of two numbers of 256 bits.

function min(uint256 a, uint256 b) internal pure returns (uint256 result);

mul

function mul(uint256 a, uint256 b) internal pure returns (uint256);

div

function div(uint256 a, uint256 b, bool roundUp) internal pure returns (uint256);

divDown

function divDown(uint256 a, uint256 b) internal pure returns (uint256);

divUp

function divUp(uint256 a, uint256 b) internal pure returns (uint256 result);