| layout | title |
|---|---|
default |
Exponential |
View Source: contracts/Exponential.sol
↗ Extends: ErrorReporter, CarefulMath ↘ Derived Contracts: AlkemiEarnPublic, AlkemiEarnVerified, AlkemiRateModel, ExchangeRateModel, PriceOracle
{{ContractName}}
struct Exp {
uint256 mantissa
}struct ExpNegative {
int256 mantissa
}Constants & Variables
uint256 internal constant expScale;
uint256 internal constant halfExpScale;
uint256 internal constant mantissaOne;
uint256 internal constant mantissaOneTenth;- getExp(uint256 num, uint256 denom)
- addExp(struct Exponential.Exp a, struct Exponential.Exp b)
- addExpNegative(struct Exponential.Exp a, struct Exponential.ExpNegative b)
- subExp(struct Exponential.Exp a, struct Exponential.Exp b)
- subExpNegative(struct Exponential.Exp a, struct Exponential.Exp b)
- mulScalar(struct Exponential.Exp a, uint256 scalar)
- divScalar(struct Exponential.Exp a, uint256 scalar)
- divScalarByExp(uint256 scalar, struct Exponential.Exp divisor)
- mulExp(struct Exponential.Exp a, struct Exponential.Exp b)
- divExp(struct Exponential.Exp a, struct Exponential.Exp b)
- truncate(struct Exponential.Exp exp)
- lessThanExp(struct Exponential.Exp left, struct Exponential.Exp right)
- lessThanOrEqualExp(struct Exponential.Exp left, struct Exponential.Exp right)
- greaterThanExp(struct Exponential.Exp left, struct Exponential.Exp right)
- isZeroExp(struct Exponential.Exp value)
Creates an exponential from numerator and denominator values.
Note: Returns an error if (num * 10e18) > MAX_INT,
or if denom is zero.
function getExp(uint256 num, uint256 denom) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)Arguments
| Name | Type | Description |
|---|---|---|
| num | uint256 | |
| denom | uint256 |
Adds two exponentials, returning a new exponential.
function addExp(struct Exponential.Exp a, struct Exponential.Exp b) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)Arguments
| Name | Type | Description |
|---|---|---|
| a | struct Exponential.Exp | |
| b | struct Exponential.Exp |
Adds two exponentials, returning a new exponential.
function addExpNegative(struct Exponential.Exp a, struct Exponential.ExpNegative b) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)Arguments
| Name | Type | Description |
|---|---|---|
| a | struct Exponential.Exp | |
| b | struct Exponential.ExpNegative |
Subtracts two exponentials, returning a new exponential.
function subExp(struct Exponential.Exp a, struct Exponential.Exp b) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)Arguments
| Name | Type | Description |
|---|---|---|
| a | struct Exponential.Exp | |
| b | struct Exponential.Exp |
Subtracts two exponentials, returning a new exponential.
function subExpNegative(struct Exponential.Exp a, struct Exponential.Exp b) internal pure
returns(enum ErrorReporter.Error, struct Exponential.ExpNegative)Arguments
| Name | Type | Description |
|---|---|---|
| a | struct Exponential.Exp | |
| b | struct Exponential.Exp |
Multiply an Exp by a scalar, returning a new Exp.
function mulScalar(struct Exponential.Exp a, uint256 scalar) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)Arguments
| Name | Type | Description |
|---|---|---|
| a | struct Exponential.Exp | |
| scalar | uint256 |
Divide an Exp by a scalar, returning a new Exp.
function divScalar(struct Exponential.Exp a, uint256 scalar) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)Arguments
| Name | Type | Description |
|---|---|---|
| a | struct Exponential.Exp | |
| scalar | uint256 |
Divide a scalar by an Exp, returning a new Exp.
function divScalarByExp(uint256 scalar, struct Exponential.Exp divisor) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)Arguments
| Name | Type | Description |
|---|---|---|
| scalar | uint256 | |
| divisor | struct Exponential.Exp |
Multiplies two exponentials, returning a new exponential.
function mulExp(struct Exponential.Exp a, struct Exponential.Exp b) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)Arguments
| Name | Type | Description |
|---|---|---|
| a | struct Exponential.Exp | |
| b | struct Exponential.Exp |
Divides two exponentials, returning a new exponential. (a/scale) / (b/scale) = (a/scale) * (scale/b) = a/b, which we can scale as an Exp by calling getExp(a.mantissa, b.mantissa)
function divExp(struct Exponential.Exp a, struct Exponential.Exp b) internal pure
returns(enum ErrorReporter.Error, struct Exponential.Exp)Arguments
| Name | Type | Description |
|---|---|---|
| a | struct Exponential.Exp | |
| b | struct Exponential.Exp |
Truncates the given exp to a whole number value. For example, truncate(Exp{mantissa: 15 * (10**18)}) = 15
function truncate(struct Exponential.Exp exp) internal pure
returns(uint256)Arguments
| Name | Type | Description |
|---|---|---|
| exp | struct Exponential.Exp |
Checks if first Exp is less than second Exp.
function lessThanExp(struct Exponential.Exp left, struct Exponential.Exp right) internal pure
returns(bool)Arguments
| Name | Type | Description |
|---|---|---|
| left | struct Exponential.Exp | |
| right | struct Exponential.Exp |
Checks if left Exp <= right Exp.
function lessThanOrEqualExp(struct Exponential.Exp left, struct Exponential.Exp right) internal pure
returns(bool)Arguments
| Name | Type | Description |
|---|---|---|
| left | struct Exponential.Exp | |
| right | struct Exponential.Exp |
Checks if first Exp is greater than second Exp.
function greaterThanExp(struct Exponential.Exp left, struct Exponential.Exp right) internal pure
returns(bool)Arguments
| Name | Type | Description |
|---|---|---|
| left | struct Exponential.Exp | |
| right | struct Exponential.Exp |
returns true if Exp is exactly zero
function isZeroExp(struct Exponential.Exp value) internal pure
returns(bool)Arguments
| Name | Type | Description |
|---|---|---|
| value | struct Exponential.Exp |