MathHelper
Functions
add
Returns the addition of two uint256.
function add(uint256 a, uint256 b) external pure returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint256 | |
| b | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
sub
Returns the subtraction of two uint256.
function sub(uint256 a, uint256 b) external pure returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint256 | |
| b | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
mul
Returns the multiplication of two uint256.
function mul(uint256 a, uint256 b) external pure returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint256 | |
| b | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
div
Returns the division of two uint256.
function div(uint256 a, uint256 b) external pure returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint256 | |
| b | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
ceilDiv
See Math.
function ceilDiv(uint256 a, uint256 b) external pure returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint256 | |
| b | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
mulDiv
See Math.
function mulDiv(uint256 x, uint256 y, uint256 denominator) external pure returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| x | uint256 | |
| y | uint256 | |
| denominator | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
ceilMulDiv
See Math.
function ceilMulDiv(uint256 x, uint256 y, uint256 denominator) external pure returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| x | uint256 | |
| y | uint256 | |
| denominator | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
sqrt
See Math.
function sqrt(uint256 a) external pure returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
average
See Math.
function average(uint256 a, uint256 b) external pure returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint256 | |
| b | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
ternary
See Math.
function ternary(bool condition, uint256 a, uint256 b) external pure returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| condition | bool | |
| a | uint256 | |
| b | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
max
See Math.
function max(uint256 a, uint256 b) external pure returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint256 | |
| b | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
min
See Math.
function min(uint256 a, uint256 b) external pure returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint256 | |
| b | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
log2
See Math.
function log2(uint256 x) external pure returns (uint256 r);Parameters
| Name | Type | Description |
|---|---|---|
| x | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| r | uint256 |
log10
See Math.
function log10(uint256 x) external pure returns (uint256 r);Parameters
| Name | Type | Description |
|---|---|---|
| x | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| r | uint256 |
log256
See Math.
function log256(uint256 x) external pure returns (uint256 r);Parameters
| Name | Type | Description |
|---|---|---|
| x | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| r | uint256 |
eq
Returns whether two values are equal.
function eq(uint256 a, uint256 b) external pure returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint256 | |
| b | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
lt
Returns whether a value is less than another value.
function lt(uint256 a, uint256 b) external pure returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint256 | |
| b | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
lte
Returns whether a value is less than or equal to another value.
function lte(uint256 a, uint256 b) external pure returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint256 | |
| b | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
gt
Returns whether a value is greater than another value.
function gt(uint256 a, uint256 b) external pure returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint256 | |
| b | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
gte
Returns whether a value is greater than or equal to another value.
function gte(uint256 a, uint256 b) external pure returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| a | uint256 | |
| b | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
uint128Max
Returns the maximum value of uint128.
function uint128Max() external pure returns (uint128);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint128 |
uint256Max
Returns the maximum value of uint256.
function uint256Max() external pure returns (uint256);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
scaleAmount
Scales amount from fromDecimals to toDecimals.
Converts token amounts between different decimal precisions.
Note:
- warning: Scaling down reduces precision due to integer division truncation.
function scaleAmount(uint256 amount, uint8 fromDecimals, uint8 toDecimals) public pure returns (uint256 scaled);Parameters
| Name | Type | Description |
|---|---|---|
| amount | uint256 | The amount to scale. |
| fromDecimals | uint8 | The source decimal precision. |
| toDecimals | uint8 | The target decimal precision. |
Returns
| Name | Type | Description |
|---|---|---|
| scaled | uint256 | The amount adjusted to the target decimals. |
Errors
DecimalsOutOfRange
error DecimalsOutOfRange();