Skip to main content

FixedPoint

Git Source

State Variables

ONE

uint256 internal constant ONE = 1e18

TWO

uint256 internal constant TWO = 2 * ONE

FOUR

uint256 internal constant FOUR = 4 * ONE

MAX_POW_RELATIVE_ERROR

uint256 internal constant MAX_POW_RELATIVE_ERROR = 10000

MIN_POW_BASE_FREE_EXPONENT

uint256 internal constant MIN_POW_BASE_FREE_EXPONENT = 0.7e18

Functions

add

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

sub

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

mulDown

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

mulUp

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

divDown

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

divUp

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

powDown

Returns x^y, assuming both are fixed point numbers, rounding down. The result is guaranteed to not be above the true value (that is, the error function expected - actual is always positive).

function powDown(uint256 x, uint256 y) internal pure returns (uint256);

powUp

Returns x^y, assuming both are fixed point numbers, rounding up. The result is guaranteed to not be below the true value (that is, the error function expected - actual is always negative).

function powUp(uint256 x, uint256 y) internal pure returns (uint256);

complement

Returns the complement of a value (1 - x), capped to 0 if x is larger than 1. Useful when computing the complement for values with some level of relative error, as it strips this error and prevents intermediate negative values.

function complement(uint256 x) internal pure returns (uint256 result);