ExponentialNoError
Title: Exponential module for storing fixed-precision decimals
Author: Compound
Exp is a struct which stores decimals with a fixed precision of 18 decimal places.
Thus, if we wanted to store the 5.1, mantissa would store 5.1e18.
That is: Exp({mantissa: 5100000000000000000}).
State Variables
EXP_SCALE
Scale factor for exponential calculations
uint256 internal constant EXP_SCALE = 1e18
DOUBLE_SCALE
Scale factor for double precision calculations
uint256 internal constant DOUBLE_SCALE = 1e36
HALF_EXP_SCALE
Half of the scale factor for exponential calculations
uint256 internal constant HALF_EXP_SCALE = EXP_SCALE / 2
MANTISSA_ONE
Mantissa value for one
uint256 internal constant MANTISSA_ONE = EXP_SCALE
Functions
truncate
Truncates the given exp to a whole number value. For example, truncate(Exp{mantissa: 15 * EXP_SCALE}) = 15
function truncate(Exp memory exp) internal pure returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
exp | Exp | The exp to truncate. |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The truncated value. |
mul_ScalarTruncate
Multiply an Exp by a scalar, then truncate to return an unsigned integer.
function mul_ScalarTruncate(Exp memory a, uint256 scalar) internal pure returns (uint256);
mul_ScalarTruncateAddUInt
Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer.
function mul_ScalarTruncateAddUInt(Exp memory a, uint256 scalar, uint256 addend) internal pure returns (uint256);
lessThanExp
Checks if first Exp is less than second Exp.
function lessThanExp(Exp memory left, Exp memory right) internal pure returns (bool);
lessThanOrEqualExp
Checks if left Exp <= right Exp.
function lessThanOrEqualExp(Exp memory left, Exp memory right) internal pure returns (bool);
greaterThanExp
Checks if left Exp > right Exp.
function greaterThanExp(Exp memory left, Exp memory right) internal pure returns (bool);
isZeroExp
returns true if Exp is exactly zero
function isZeroExp(Exp memory value) internal pure returns (bool);
safe224
function safe224(uint256 n, string memory errorMessage) internal pure returns (uint224);
safe32
function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32);
add_
function add_(Exp memory a, Exp memory b) internal pure returns (Exp memory);
add_
function add_(Double memory a, Double memory b) internal pure returns (Double memory);
add_
function add_(uint256 a, uint256 b) internal pure returns (uint256);
sub_
function sub_(Exp memory a, Exp memory b) internal pure returns (Exp memory);
sub_
function sub_(Double memory a, Double memory b) internal pure returns (Double memory);
sub_
function sub_(uint256 a, uint256 b) internal pure returns (uint256);
mul_
function mul_(Exp memory a, Exp memory b) internal pure returns (Exp memory);
mul_
function mul_(Exp memory a, uint256 b) internal pure returns (Exp memory);
mul_
function mul_(uint256 a, Exp memory b) internal pure returns (uint256);
mul_
function mul_(Double memory a, Double memory b) internal pure returns (Double memory);
mul_
function mul_(Double memory a, uint256 b) internal pure returns (Double memory);
mul_
function mul_(uint256 a, Double memory b) internal pure returns (uint256);
mul_
function mul_(uint256 a, uint256 b) internal pure returns (uint256);
div_
function div_(Exp memory a, Exp memory b) internal pure returns (Exp memory);
div_
function div_(Exp memory a, uint256 b) internal pure returns (Exp memory);
div_
function div_(uint256 a, Exp memory b) internal pure returns (uint256);
div_
function div_(Double memory a, Double memory b) internal pure returns (Double memory);
div_
function div_(Double memory a, uint256 b) internal pure returns (Double memory);
div_
function div_(uint256 a, Double memory b) internal pure returns (uint256);
div_
function div_(uint256 a, uint256 b) internal pure returns (uint256);
divUp_
function divUp_(uint256 a, uint256 b) internal pure returns (uint256);
divUp_
function divUp_(uint256 a, Exp memory b) internal pure returns (uint256);
fraction
function fraction(uint256 a, uint256 b) internal pure returns (Double memory);
Structs
Exp
struct Exp {
uint256 mantissa;
}
Double
struct Double {
uint256 mantissa;
}