Skip to main content

CarefulMath

CarefulMath​

Derived from OpenZeppelin's SafeMath library https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol

MathError​

Possible error codes that we can return

enum MathError {
NO_ERROR,
DIVISION_BY_ZERO,
INTEGER_OVERFLOW,
INTEGER_UNDERFLOW
}

mulUInt​

function mulUInt(uint256 a, uint256 b) internal pure returns (enum CarefulMath.MathError, uint256)

Multiplies two numbers, returns an error on overflow.

divUInt​

function divUInt(uint256 a, uint256 b) internal pure returns (enum CarefulMath.MathError, uint256)

Integer division of two numbers, truncating the quotient.

subUInt​

function subUInt(uint256 a, uint256 b) internal pure returns (enum CarefulMath.MathError, uint256)

Subtracts two numbers, returns an error on overflow (i.e. if subtrahend is greater than minuend).

addUInt​

function addUInt(uint256 a, uint256 b) internal pure returns (enum CarefulMath.MathError, uint256)

Adds two numbers, returns an error on overflow.

addThenSubUInt​

function addThenSubUInt(uint256 a, uint256 b, uint256 c) internal pure returns (enum CarefulMath.MathError, uint256)

add a and b and then subtract c

min​

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

min and max functions

max​

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

MAXUINT​

uint256 MAXUINT

MAXUINT96​

uint256 MAXUINT96

MAXUINT24​

uint256 MAXUINT24