UD60x18
UD60x18
Alias for uint256
. See source code for documentation.
uUNIT
UNIT
uHALF_UNIT
uUNIT_SQUARED
ZERO
uEXP2_MAX_INPUT
EXP2_MAX_INPUT
PRBMath_UD60x18_Log_InputTooSmall
Thrown when taking the logarithm of a number less than 1.
error PRBMath_UD60x18_Log_InputTooSmall(UD60x18 x)
PRBMath_UD60x18_Exp2_InputTooBig
Thrown when taking the binary exponent of a base greater than 192e18.
error PRBMath_UD60x18_Exp2_InputTooBig(UD60x18 x)
wrap
Wraps a uint256 number into the UD60x18 value type.
function wrap(uint256 x) internal pure returns (UD60x18 result)
unwrap
Unwraps a UD60x18 number into uint256.
function unwrap(UD60x18 x) internal pure returns (uint256 result)
pow
Raises x to the power of y.
For , the following standard formula is used:
For , since the unsigned {log2} is undefined, an equivalent formula is used:
function pow(UD60x18 x, UD60x18 y) internal pure returns (UD60x18 result)
Notes:
- Refer to the notes in {log2} and {mul}.
- Returns
UNIT
for 0^0. - It may not perform well with very small values of x. Consider using SD59x18 as an alternative.
Requirements:
- Refer to the requirements in {exp2}, {log2}, and {mul}.
Parameters
Name | Type | Description |
---|---|---|
x | UD60x18 | The base as a UD60x18 number. |
y | UD60x18 | The exponent as a UD60x18 number. |
Fields
Name | Type | Description |
---|
Return Values
Name | Type | Description |
---|---|---|
result | UD60x18 | The result as a UD60x18 number. |
log2
Calculates the binary logarithm of x using the iterative approximation algorithm:
For , the input is inverted:
function log2(UD60x18 x) internal pure returns (UD60x18 result)
See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation
Notes:
- Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.
Requirements:
- x must be greater than zero.
Parameters
Name | Type | Description |
---|---|---|
x | UD60x18 | The UD60x18 number for which to calculate the binary logarithm. |
Fields
Name | Type | Description |
---|
Return Values
Name | Type | Description |
---|---|---|
result | UD60x18 | The binary logarithm as a UD60x18 number. |
mul
Multiplies two UD60x18 numbers together, returning a new UD60x18 number.
function mul(UD60x18 x, UD60x18 y) internal pure returns (UD60x18 result)
Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
Notes:
- Refer to the notes in {Common.mulDiv}.
Requirements:
- Refer to the requirements in {Common.mulDiv}.
See the documentation in {Common.mulDiv18}.
Parameters
Name | Type | Description |
---|---|---|
x | UD60x18 | The multiplicand as a UD60x18 number. |
y | UD60x18 | The multiplier as a UD60x18 number. |
Fields
Name | Type | Description |
---|
Return Values
Name | Type | Description |
---|---|---|
result | UD60x18 | The product as a UD60x18 number. |
div
Divides two UD60x18 numbers, returning a new UD60x18 number.
function div(UD60x18 x, UD60x18 y) internal pure returns (UD60x18 result)
Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
Notes:
- Refer to the notes in {Common.mulDiv}.
Requirements:
- Refer to the requirements in {Common.mulDiv}.
Parameters
Name | Type | Description |
---|---|---|
x | UD60x18 | The numerator as a UD60x18 number. |
y | UD60x18 | The denominator as a UD60x18 number. |
Fields
Name | Type | Description |
---|
exp2
Calculates the binary exponent of x using the binary fraction method.
function exp2(UD60x18 x) internal pure returns (UD60x18 result)
See https://ethereum.stackexchange.com/q/79903/24693
Requirements:
- x must be less than 192e18.
- The result must fit in UD60x18.
Parameters
Name | Type | Description |
---|---|---|
x | UD60x18 | The exponent as a UD60x18 number. |
Fields
Name | Type | Description |
---|
Return Values
Name | Type | Description |
---|---|---|
result | UD60x18 | The result as a UD60x18 number. |