Exponential.sol

Structs

Exp

1
struct Exp {
2
uint256 mantissa
3
}
Copied!

Contract Members

Constants & Variables
1
uint256 internal constant expScale;
2
uint256 internal constant halfExpScale;
3
uint256 internal constant mantissaOne;
4
uint256 internal constant mantissaOneTenth;
Copied!

Functions

  • getExp(uint256 num, uint256 denom)
  • addExp(struct Exponential.Exp a, struct Exponential.Exp b)
  • subExp(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)

getExp

Creates an exponential from numerator and denominator values. Note: Returns an error if (num * 10e18) > MAX_INT, or if denom is zero.
1
function getExp(uint256 num, uint256 denom) internal pure
2
returns(enum ErrorReporter.Error, struct Exponential.Exp)
Copied!
Arguments
Name
Type
Description
num
uint256
denom
uint256

addExp

Adds two exponentials, returning a new exponential.
1
function addExp(struct Exponential.Exp a, struct Exponential.Exp b) internal pure
2
returns(enum ErrorReporter.Error, struct Exponential.Exp)
Copied!
Arguments
Name
Type
Description
a
struct Exponential.Exp
b
struct Exponential.Exp

subExp

Subtracts two exponentials, returning a new exponential.
1
function subExp(struct Exponential.Exp a, struct Exponential.Exp b) internal pure
2
returns(enum ErrorReporter.Error, struct Exponential.Exp)
Copied!
Arguments
Name
Type
Description
a
struct Exponential.Exp
b
struct Exponential.Exp

mulScalar

Multiply an Exp by a scalar, returning a new Exp.
1
function mulScalar(struct Exponential.Exp a, uint256 scalar) internal pure
2
returns(enum ErrorReporter.Error, struct Exponential.Exp)
Copied!
Arguments
Name
Type
Description
a
struct Exponential.Exp
scalar
uint256

divScalar

Divide an Exp by a scalar, returning a new Exp.
1
function divScalar(struct Exponential.Exp a, uint256 scalar) internal pure
2
returns(enum ErrorReporter.Error, struct Exponential.Exp)
Copied!
Arguments
Name
Type
Description
a
struct Exponential.Exp
scalar
uint256

divScalarByExp

Divide a scalar by an Exp, returning a new Exp.
1
function divScalarByExp(uint256 scalar, struct Exponential.Exp divisor) internal pure
2
returns(enum ErrorReporter.Error, struct Exponential.Exp)
Copied!
Arguments
Name
Type
Description
scalar
uint256
divisor
struct Exponential.Exp

mulExp

Multiplies two exponentials, returning a new exponential.
1
function mulExp(struct Exponential.Exp a, struct Exponential.Exp b) internal pure
2
returns(enum ErrorReporter.Error, struct Exponential.Exp)
Copied!
Arguments
Name
Type
Description
a
struct Exponential.Exp
b
struct Exponential.Exp

divExp

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)
1
function divExp(struct Exponential.Exp a, struct Exponential.Exp b) internal pure
2
returns(enum ErrorReporter.Error, struct Exponential.Exp)
Copied!
Arguments
Name
Type
Description
a
struct Exponential.Exp
b
struct Exponential.Exp

truncate

Truncates the given exp to a whole number value. For example, truncate(Exp{mantissa: 15 (10*18)}) = 15
1
function truncate(struct Exponential.Exp exp) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
exp
struct Exponential.Exp

lessThanExp

Checks if first Exp is less than second Exp.
1
function lessThanExp(struct Exponential.Exp left, struct Exponential.Exp right) internal pure
2
returns(bool)
Copied!
Arguments
Name
Type
Description
left
struct Exponential.Exp
right
struct Exponential.Exp

lessThanOrEqualExp

Checks if left Exp <= right Exp.
1
function lessThanOrEqualExp(struct Exponential.Exp left, struct Exponential.Exp right) internal pure
2
returns(bool)
Copied!
Arguments
Name
Type
Description
left
struct Exponential.Exp
right
struct Exponential.Exp

greaterThanExp

Checks if first Exp is greater than second Exp.
1
function greaterThanExp(struct Exponential.Exp left, struct Exponential.Exp right) internal pure
2
returns(bool)
Copied!
Arguments
Name
Type
Description
left
struct Exponential.Exp
right
struct Exponential.Exp

isZeroExp

returns true if Exp is exactly zero
1
function isZeroExp(struct Exponential.Exp value) internal pure
2
returns(bool)
Copied!
Arguments
Name
Type
Description
value
struct Exponential.Exp