add
Adds two FPSigned
s, reverting on overflow.
function add(FPSigned a, FPSigned b) internal pure returns (FPSigned)
Parameters
Name | Type | Description |
---|
a | FPSigned | a FPSigned. |
b | FPSigned | a FPSigned. |
Return Values
Name | Type | Description |
---|
[0] | FPSigned | the sum of a and b . |
sub
Subtracts two FPSigned
s, reverting on overflow.
function sub(FPSigned a, FPSigned b) internal pure returns (FPSigned)
Parameters
Name | Type | Description |
---|
a | FPSigned | a FPSigned. |
b | FPSigned | a FPSigned. |
Return Values
Name | Type | Description |
---|
[0] | FPSigned | the difference of a and b . |
mul
Multiplies two FPSigned
s, reverting on overflow.
function mul(FPSigned a, FPSigned b) internal pure returns (FPSigned)
This will "floor" the product.
Parameters
Name | Type | Description |
---|
a | FPSigned | a FPSigned. |
b | FPSigned | a FPSigned. |
Return Values
Name | Type | Description |
---|
[0] | FPSigned | the product of a and b . |
neg
Negate a FPSigned
function neg(FPSigned a) internal pure returns (FPSigned)
Parameters
Name | Type | Description |
---|
a | FPSigned | Value to negate |
Return Values
Name | Type | Description |
---|
[0] | FPSigned | FPSigned a * -1 |
div
Divides one FPSigned
by a FPSigned
, reverting on overflow or
division by 0. This will "floor" the quotient.
function div(FPSigned a, FPSigned b) internal pure returns (FPSigned)
There are two caveats with this computation:
- Max value for
a
is ~10^41, otherwise an intermediate value overflows.
10^41 is stored internally as int256 10^59
- Results that can't be represented exactly are truncated, not rounded.
E.g., 2 / 3 = 0.6 repeating, which would round to 0.666666666666666667,
but this computation produces the result 0.666666666666666666.
Parameters
Name | Type | Description |
---|
a | FPSigned | a FPSigned numerator. |
b | FPSigned | a FPSigned denominator. |
Return Values
Name | Type | Description |
---|
[0] | FPSigned | the quotient of a divided by b . |
isEqual
Whether a
is equal to b
.
function isEqual(FPSigned a, FPSigned b) internal pure returns (bool)
Parameters
Name | Type | Description |
---|
a | FPSigned | a FPSigned. |
b | FPSigned | a FPSigned. |
Return Values
Name | Type | Description |
---|
[0] | bool | True if equal, or False. |
isNotEqual
Whether a
is equal to b
.
function isNotEqual(FPSigned a, FPSigned b) internal pure returns (bool)
Parameters
Name | Type | Description |
---|
a | FPSigned | a FPSigned. |
b | FPSigned | a FPSigned. |
Return Values
Name | Type | Description |
---|
[0] | bool | True if equal, or False. |
isGreaterThan
Whether a
is greater than b
.
function isGreaterThan(FPSigned a, FPSigned b) internal pure returns (bool)
Parameters
Name | Type | Description |
---|
a | FPSigned | a FPSigned. |
b | FPSigned | a FPSigned. |
Return Values
Name | Type | Description |
---|
[0] | bool | True if a > b , or False. |
isGreaterThanOrEqual
Whether a
is greater than or equal to b
.
function isGreaterThanOrEqual(FPSigned a, FPSigned b) internal pure returns (bool)
Parameters
Name | Type | Description |
---|
a | FPSigned | a FPSigned. |
b | FPSigned | a FPSigned. |
Return Values
Name | Type | Description |
---|
[0] | bool | True if a >= b , or False. |
isLessThan
Whether a
is less than b
.
function isLessThan(FPSigned a, FPSigned b) internal pure returns (bool)
Parameters
Name | Type | Description |
---|
a | FPSigned | a FPSigned. |
b | FPSigned | a FPSigned. |
Return Values
Name | Type | Description |
---|
[0] | bool | True if a < b , or False. |
isLessThanOrEqual
Whether a
is less than or equal to b
.
function isLessThanOrEqual(FPSigned a, FPSigned b) internal pure returns (bool)
Parameters
Name | Type | Description |
---|
a | FPSigned | a FPSigned. |
b | FPSigned | a FPSigned. |
Return Values
Name | Type | Description |
---|
[0] | bool | True if a <= b , or False. |
abs
Absolute value of a FPSigned
function abs(FPSigned value) internal pure returns (FPUnsigned)
Parameters
Name | Type | Description |
---|
value | FPSigned | Value to get abs() of |
Return Values
Name | Type | Description |
---|
[0] | FPUnsigned | FPUnsigned |
trunc
Convert a FPUnsigned to uint, "truncating" any decimal portion.
function trunc(FPSigned value) internal pure returns (int256)
roundFloor
Round a FPSigned towards -∞, not towards 0 like normal rounding.
function roundFloor(FPSigned value) internal pure returns (int256)
Useful to handle "dust" from trades. If the P/L is a trader gain/vault
loss, then fractional gain of trade should be ignored. If the P/L is a
trader loss/vault gain, then fractional loss should be rounded "up" to -1.
Parameters
Name | Type | Description |
---|
value | FPSigned | Signed value to round + trunc |
Return Values
Name | Type | Description |
---|
[0] | int256 | int256 value with any decimal component rounded towards -∞ |