ABDKMath64x64
The ABDKMath64x64 library provides fixed-point arithmetic operations.
mulu
Calculate x * y
rounding down, where x
is a signed 64.64 fixed-point number, and y
is an unsigned 256-bit integer. Revert on overflow.
function mulu (
int128 x,
uint256 y) internal pure returns (uint256)
Parameters:
x
int128
Signed 64.64 fixed-point number.
y
uint
Unsigned 256-bit integer.
Return Values:
None
uint
Unsigned 256-bit integer.
divu
Calculate x / y
rounding towards zero, where x
and y
are unsigned 256-bit integer numbers. Revert on overflow or when y
is zero.
function divu (
uint256 x,
uint256 y) internal pure returns (int128)
Parameters:
x
uint
Unsigned 256-bit integer.
y
uint
Unsigned 256-bit integer.
Return Values:
None
int128
Signed 64.64 fixed-point number.
exp_2
The exp_2
function calculates the binary exponent of a given signed 64.64-bit fixed-point number, x
. This function utilizes a series of conditional multiplications based on the bits set in the binary representation of x
. The purpose is to efficiently approximate the value of 2^x
without resorting to iterative calculations, ensuring that the result is a signed 64.64-bit fixed-point number.
function exp_2 (
int128 x) internal pure returns (int128)
Parameters:
x
int128
Signed 64.64 fixed-point number.
Return Values:
None
int128
Signed 64.64 fixed-point number.
divuu
Internal function to calculate x / y rounding towards zero, where x and y are unsigned 256-bit integer numbers. Revert on overflow or when y is zero.
This function is designed to provide a robust and efficient method for dividing two uint256
numbers in a way that accounts for various scenarios, including large numbers and potential overflow issues. The approach combines bit manipulation, conditional statements, and explicit checks to balance performance and accuracy.
function divuu (
uint256 x,
uint256 y) private pure returns (uint128)
Parameters:
x
uint
Unsigned 256-bit integer.
y
uint
Unsigned 256-bit integer.
Return Values:
None
uint128
Unsigned 64.64 fixed-point number.
This library plays a pivotal role in Dyson Finance, notably in the divu
and exp_2
functions, which are extensively employed. These functions are integral to several critical calculations within various contracts:
// Farm.sol
function _calcRewardAmount(uint _reserve, uint _amount, uint _w) internal pure returns (uint reward)
// Pair.sol
function calcNewFeeRatio(uint64 _oldFeeRatio, uint _elapsedTime) public view returns (uint64 _newFeeRatio)
// sDYSON.sol
function stakingRate(uint lockDuration) external view returns (uint rate)
Last updated