Accumulator

Git Source

Library to operate on the liquidation multiplier accumulator values (512-bit integers).

This is a wrapper for HugeUint that is deployed to its own address and called via delegatecall.

Functions

add

Calculates the sum a + b of two 512-bit unsigned integers.

function add(HugeUint.Uint512 memory a, HugeUint.Uint512 memory b)
    external
    pure
    returns (HugeUint.Uint512 memory res_);

Parameters

NameTypeDescription
aHugeUint.Uint512The first operand.
bHugeUint.Uint512The second operand.

Returns

NameTypeDescription
res_HugeUint.Uint512The sum of a and b.

sub

Calculates the difference a - b of two 512-bit unsigned integers.

function sub(HugeUint.Uint512 memory a, HugeUint.Uint512 memory b)
    external
    pure
    returns (HugeUint.Uint512 memory res_);

Parameters

NameTypeDescription
aHugeUint.Uint512The first operand.
bHugeUint.Uint512The second operand.

Returns

NameTypeDescription
res_HugeUint.Uint512The difference a - b.

mul

Calculates the product a * b of two 256-bit unsigned integers using the Chinese remainder theorem.

function mul(uint256 a, uint256 b) external pure returns (HugeUint.Uint512 memory res_);

Parameters

NameTypeDescription
auint256The first operand.
buint256The second operand.

Returns

NameTypeDescription
res_HugeUint.Uint512The product a * b of the operands as an unsigned 512-bit integer.

mul

Calculates the product a * b of a 512-bit unsigned integer and a 256-bit unsigned integer.

function mul(HugeUint.Uint512 memory a, uint256 b) external pure returns (HugeUint.Uint512 memory res_);

Parameters

NameTypeDescription
aHugeUint.Uint512The first operand.
buint256The second operand.

Returns

NameTypeDescription
res_HugeUint.Uint512The product a * b of the operands as an unsigned 512-bit integer.

div

Calculates the division floor(a / b) of a 512-bit unsigned integer by an unsigned 256-bit integer.

function div(HugeUint.Uint512 memory a, uint256 b) external pure returns (uint256 res_);

Parameters

NameTypeDescription
aHugeUint.Uint512The numerator as a 512-bit unsigned integer.
buint256The denominator as a 256-bit unsigned integer.

Returns

NameTypeDescription
res_uint256The division floor(a / b) of the operands as an unsigned 256-bit integer.

div

Computes the division floor(a/b) of two 512-bit integers, knowing the result fits inside a uint256.

function div(HugeUint.Uint512 memory a, HugeUint.Uint512 memory b) external pure returns (uint256 res_);

Parameters

NameTypeDescription
aHugeUint.Uint512The numerator as a 512-bit integer.
bHugeUint.Uint512The denominator as a 512-bit integer.

Returns

NameTypeDescription
res_uint256The quotient floor(a/b).