Exponential module for storing fixed-precision decimals (ExponentialNoError.sol)
↘ Derived Contracts: RewardControl
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}).

Structs

Exp

1
struct Exp {
2
uint256 mantissa
3
}
Copied!

Double

1
struct Double {
2
uint256 mantissa
3
}
Copied!

Contract Members

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

Functions

  • truncate(struct ExponentialNoError.Exp exp)
  • mul_ScalarTruncate(struct ExponentialNoError.Exp a, uint256 scalar)
  • mul_ScalarTruncateAddUInt(struct ExponentialNoError.Exp a, uint256 scalar, uint256 addend)
  • lessThanExp(struct ExponentialNoError.Exp left, struct ExponentialNoError.Exp right)
  • lessThanOrEqualExp(struct ExponentialNoError.Exp left, struct ExponentialNoError.Exp right)
  • greaterThanExp(struct ExponentialNoError.Exp left, struct ExponentialNoError.Exp right)
  • isZeroExp(struct ExponentialNoError.Exp value)
  • safe224(uint256 n, string errorMessage)
  • safe32(uint256 n, string errorMessage)
  • add_(struct ExponentialNoError.Exp a, struct ExponentialNoError.Exp b)
  • add_(struct ExponentialNoError.Double a, struct ExponentialNoError.Double b)
  • add_(uint256 a, uint256 b)
  • add_(uint256 a, uint256 b, string errorMessage)
  • sub_(struct ExponentialNoError.Exp a, struct ExponentialNoError.Exp b)
  • sub_(struct ExponentialNoError.Double a, struct ExponentialNoError.Double b)
  • sub_(uint256 a, uint256 b)
  • sub_(uint256 a, uint256 b, string errorMessage)
  • mul_(struct ExponentialNoError.Exp a, struct ExponentialNoError.Exp b)
  • mul_(struct ExponentialNoError.Exp a, uint256 b)
  • mul_(uint256 a, struct ExponentialNoError.Exp b)
  • mul_(struct ExponentialNoError.Double a, struct ExponentialNoError.Double b)
  • mul_(struct ExponentialNoError.Double a, uint256 b)
  • mul_(uint256 a, struct ExponentialNoError.Double b)
  • mul_(uint256 a, uint256 b)
  • mul_(uint256 a, uint256 b, string errorMessage)
  • div_(struct ExponentialNoError.Exp a, struct ExponentialNoError.Exp b)
  • div_(struct ExponentialNoError.Exp a, uint256 b)
  • div_(uint256 a, struct ExponentialNoError.Exp b)
  • div_(struct ExponentialNoError.Double a, struct ExponentialNoError.Double b)
  • div_(struct ExponentialNoError.Double a, uint256 b)
  • div_(uint256 a, struct ExponentialNoError.Double b)
  • div_(uint256 a, uint256 b)
  • div_(uint256 a, uint256 b, string errorMessage)
  • fraction(uint256 a, uint256 b)

truncate

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

mul_ScalarTruncate

Multiply an Exp by a scalar, then truncate to return an unsigned integer.
1
function mul_ScalarTruncate(struct ExponentialNoError.Exp a, uint256 scalar) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
a
struct ExponentialNoError.Exp
scalar
uint256

mul_ScalarTruncateAddUInt

Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer.
1
function mul_ScalarTruncateAddUInt(struct ExponentialNoError.Exp a, uint256 scalar, uint256 addend) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
a
struct ExponentialNoError.Exp
scalar
uint256
addend
uint256

lessThanExp

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

lessThanOrEqualExp

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

greaterThanExp

Checks if left Exp > right Exp.
1
function greaterThanExp(struct ExponentialNoError.Exp left, struct ExponentialNoError.Exp right) internal pure
2
returns(bool)
Copied!
Arguments
Name
Type
Description
left
struct ExponentialNoError.Exp
right
struct ExponentialNoError.Exp

isZeroExp

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

safe224

1
function safe224(uint256 n, string errorMessage) internal pure
2
returns(uint224)
Copied!
Arguments
Name
Type
Description
n
uint256
errorMessage
string

safe32

1
function safe32(uint256 n, string errorMessage) internal pure
2
returns(uint32)
Copied!
Arguments
Name
Type
Description
n
uint256
errorMessage
string

add_

1
function add_(struct ExponentialNoError.Exp a, struct ExponentialNoError.Exp b) internal pure
2
returns(struct ExponentialNoError.Exp)
Copied!
Arguments
Name
Type
Description
a
struct ExponentialNoError.Exp
b
struct ExponentialNoError.Exp

add_

1
function add_(struct ExponentialNoError.Double a, struct ExponentialNoError.Double b) internal pure
2
returns(struct ExponentialNoError.Double)
Copied!
Arguments
Name
Type
Description
a
struct ExponentialNoError.Double
b
struct ExponentialNoError.Double

add_

1
function add_(uint256 a, uint256 b) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
a
uint256
b
uint256

add_

1
function add_(uint256 a, uint256 b, string errorMessage) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
a
uint256
b
uint256
errorMessage
string

sub_

1
function sub_(struct ExponentialNoError.Exp a, struct ExponentialNoError.Exp b) internal pure
2
returns(struct ExponentialNoError.Exp)
Copied!
Arguments
Name
Type
Description
a
struct ExponentialNoError.Exp
b
struct ExponentialNoError.Exp

sub_

1
function sub_(struct ExponentialNoError.Double a, struct ExponentialNoError.Double b) internal pure
2
returns(struct ExponentialNoError.Double)
Copied!
Arguments
Name
Type
Description
a
struct ExponentialNoError.Double
b
struct ExponentialNoError.Double

sub_

1
function sub_(uint256 a, uint256 b) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
a
uint256
b
uint256

sub_

1
function sub_(uint256 a, uint256 b, string errorMessage) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
a
uint256
b
uint256
errorMessage
string

mul_

1
function mul_(struct ExponentialNoError.Exp a, struct ExponentialNoError.Exp b) internal pure
2
returns(struct ExponentialNoError.Exp)
Copied!
Arguments
Name
Type
Description
a
struct ExponentialNoError.Exp
b
struct ExponentialNoError.Exp

mul_

1
function mul_(struct ExponentialNoError.Exp a, uint256 b) internal pure
2
returns(struct ExponentialNoError.Exp)
Copied!
Arguments
Name
Type
Description
a
struct ExponentialNoError.Exp
b
uint256

mul_

1
function mul_(uint256 a, struct ExponentialNoError.Exp b) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
a
uint256
b
struct ExponentialNoError.Exp

mul_

1
function mul_(struct ExponentialNoError.Double a, struct ExponentialNoError.Double b) internal pure
2
returns(struct ExponentialNoError.Double)
Copied!
Arguments
Name
Type
Description
a
struct ExponentialNoError.Double
b
struct ExponentialNoError.Double

mul_

1
function mul_(struct ExponentialNoError.Double a, uint256 b) internal pure
2
returns(struct ExponentialNoError.Double)
Copied!
Arguments
Name
Type
Description
a
struct ExponentialNoError.Double
b
uint256

mul_

1
function mul_(uint256 a, struct ExponentialNoError.Double b) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
a
uint256
b
struct ExponentialNoError.Double

mul_

1
function mul_(uint256 a, uint256 b) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
a
uint256
b
uint256

mul_

1
function mul_(uint256 a, uint256 b, string errorMessage) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
a
uint256
b
uint256
errorMessage
string

div_

1
function div_(struct ExponentialNoError.Exp a, struct ExponentialNoError.Exp b) internal pure
2
returns(struct ExponentialNoError.Exp)
Copied!
Arguments
Name
Type
Description
a
struct ExponentialNoError.Exp
b
struct ExponentialNoError.Exp

div_

1
function div_(struct ExponentialNoError.Exp a, uint256 b) internal pure
2
returns(struct ExponentialNoError.Exp)
Copied!
Arguments
Name
Type
Description
a
struct ExponentialNoError.Exp
b
uint256

div_

1
function div_(uint256 a, struct ExponentialNoError.Exp b) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
a
uint256
b
struct ExponentialNoError.Exp

div_

1
function div_(struct ExponentialNoError.Double a, struct ExponentialNoError.Double b) internal pure
2
returns(struct ExponentialNoError.Double)
Copied!
Arguments
Name
Type
Description
a
struct ExponentialNoError.Double
b
struct ExponentialNoError.Double

div_

1
function div_(struct ExponentialNoError.Double a, uint256 b) internal pure
2
returns(struct ExponentialNoError.Double)
Copied!
Arguments
Name
Type
Description
a
struct ExponentialNoError.Double
b
uint256

div_

1
function div_(uint256 a, struct ExponentialNoError.Double b) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
a
uint256
b
struct ExponentialNoError.Double

div_

1
function div_(uint256 a, uint256 b) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
a
uint256
b
uint256

div_

1
function div_(uint256 a, uint256 b, string errorMessage) internal pure
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
a
uint256
b
uint256
errorMessage
string

fraction

1
function fraction(uint256 a, uint256 b) internal pure
2
returns(struct ExponentialNoError.Double)
Copied!
Arguments
Name
Type
Description
a
uint256
b
uint256