Skip to main content

FixedPoint

FixedPoint#

Functions#

fromUnscaledUint(uint256 a) โ†’ struct FixedPoint.Unsigned (internal)

Constructs an Unsigned from an unscaled uint, e.g., b=5 gets stored internally as 5*(10**18).

Parameters:#

  • a: uint to convert into a FixedPoint.
isEqual(struct FixedPoint.Unsigned a, uint256 b) โ†’ bool (internal)

Whether a is equal to b.

Parameters:#

  • a: a FixedPoint.
  • b: a uint256.
isEqual(struct FixedPoint.Unsigned a, struct FixedPoint.Unsigned b) โ†’ bool (internal)

Whether a is equal to b.

Parameters:#

  • a: a FixedPoint.
  • b: a FixedPoint.
isGreaterThan(struct FixedPoint.Unsigned a, struct FixedPoint.Unsigned b) โ†’ bool (internal)

Whether a is greater than b.

Parameters:#

  • a: a FixedPoint.
  • b: a FixedPoint.
isGreaterThan(struct FixedPoint.Unsigned a, uint256 b) โ†’ bool (internal)

Whether a is greater than b.

Parameters:#

  • a: a FixedPoint.
  • b: a uint256.
isGreaterThan(uint256 a, struct FixedPoint.Unsigned b) โ†’ bool (internal)

Whether a is greater than b.

Parameters:#

  • a: a uint256.
  • b: a FixedPoint.
isGreaterThanOrEqual(struct FixedPoint.Unsigned a, struct FixedPoint.Unsigned b) โ†’ bool (internal)

Whether a is greater than or equal to b.

Parameters:#

  • a: a FixedPoint.
  • b: a FixedPoint.
isGreaterThanOrEqual(struct FixedPoint.Unsigned a, uint256 b) โ†’ bool (internal)

Whether a is greater than or equal to b.

Parameters:#

  • a: a FixedPoint.
  • b: a uint256.
isGreaterThanOrEqual(uint256 a, struct FixedPoint.Unsigned b) โ†’ bool (internal)

Whether a is greater than or equal to b.

Parameters:#

  • a: a uint256.
  • b: a FixedPoint.
isLessThan(struct FixedPoint.Unsigned a, struct FixedPoint.Unsigned b) โ†’ bool (internal)

Whether a is less than b.

Parameters:#

  • a: a FixedPoint.
  • b: a FixedPoint.
isLessThan(struct FixedPoint.Unsigned a, uint256 b) โ†’ bool (internal)

Whether a is less than b.

Parameters:#

  • a: a FixedPoint.
  • b: a uint256.
isLessThan(uint256 a, struct FixedPoint.Unsigned b) โ†’ bool (internal)

Whether a is less than b.

Parameters:#

  • a: a uint256.
  • b: a FixedPoint.
isLessThanOrEqual(struct FixedPoint.Unsigned a, struct FixedPoint.Unsigned b) โ†’ bool (internal)

Whether a is less than or equal to b.

Parameters:#

  • a: a FixedPoint.
  • b: a FixedPoint.
isLessThanOrEqual(struct FixedPoint.Unsigned a, uint256 b) โ†’ bool (internal)

Whether a is less than or equal to b.

Parameters:#

  • a: a FixedPoint.
  • b: a uint256.
isLessThanOrEqual(uint256 a, struct FixedPoint.Unsigned b) โ†’ bool (internal)

Whether a is less than or equal to b.

Parameters:#

  • a: a uint256.
  • b: a FixedPoint.
min(struct FixedPoint.Unsigned a, struct FixedPoint.Unsigned b) โ†’ struct FixedPoint.Unsigned (internal)

The minimum of a and b.

Parameters:#

  • a: a FixedPoint.
  • b: a FixedPoint.
max(struct FixedPoint.Unsigned a, struct FixedPoint.Unsigned b) โ†’ struct FixedPoint.Unsigned (internal)

The maximum of a and b.

Parameters:#

  • a: a FixedPoint.
  • b: a FixedPoint.
add(struct FixedPoint.Unsigned a, struct FixedPoint.Unsigned b) โ†’ struct FixedPoint.Unsigned (internal)

Adds two Unsigneds, reverting on overflow.

Parameters:#

  • a: a FixedPoint.
  • b: a FixedPoint.
add(struct FixedPoint.Unsigned a, uint256 b) โ†’ struct FixedPoint.Unsigned (internal)

Adds an Unsigned to an unscaled uint, reverting on overflow.

Parameters:#

  • a: a FixedPoint.
  • b: a uint256.
sub(struct FixedPoint.Unsigned a, struct FixedPoint.Unsigned b) โ†’ struct FixedPoint.Unsigned (internal)

Subtracts two Unsigneds, reverting on overflow.

Parameters:#

  • a: a FixedPoint.
  • b: a FixedPoint.
sub(struct FixedPoint.Unsigned a, uint256 b) โ†’ struct FixedPoint.Unsigned (internal)

Subtracts an unscaled uint256 from an Unsigned, reverting on overflow.

Parameters:#

  • a: a FixedPoint.
  • b: a uint256.
sub(uint256 a, struct FixedPoint.Unsigned b) โ†’ struct FixedPoint.Unsigned (internal)

Subtracts an Unsigned from an unscaled uint256, reverting on overflow.

Parameters:#

  • a: a uint256.
  • b: a FixedPoint.
mul(struct FixedPoint.Unsigned a, struct FixedPoint.Unsigned b) โ†’ struct FixedPoint.Unsigned (internal)

Multiplies two Unsigneds, reverting on overflow.

This will "floor" the product.

Parameters:#

  • a: a FixedPoint.
  • b: a FixedPoint.
mul(struct FixedPoint.Unsigned a, uint256 b) โ†’ struct FixedPoint.Unsigned (internal)

Multiplies an Unsigned and an unscaled uint256, reverting on overflow.

This will "floor" the product.

Parameters:#

  • a: a FixedPoint.
  • b: a uint256.
mulCeil(struct FixedPoint.Unsigned a, struct FixedPoint.Unsigned b) โ†’ struct FixedPoint.Unsigned (internal)

Multiplies two Unsigneds and "ceil's" the product, reverting on overflow.

Parameters:#

  • a: a FixedPoint.
  • b: a FixedPoint.
mulCeil(struct FixedPoint.Unsigned a, uint256 b) โ†’ struct FixedPoint.Unsigned (internal)

Multiplies an Unsigned and an unscaled uint256 and "ceil's" the product, reverting on overflow.

Parameters:#

  • a: a FixedPoint.
  • b: a FixedPoint.
div(struct FixedPoint.Unsigned a, struct FixedPoint.Unsigned b) โ†’ struct FixedPoint.Unsigned (internal)

Divides one Unsigned by an Unsigned, reverting on overflow or division by 0.

This will "floor" the quotient.

Parameters:#

  • a: a FixedPoint numerator.
  • b: a FixedPoint denominator.
div(struct FixedPoint.Unsigned a, uint256 b) โ†’ struct FixedPoint.Unsigned (internal)

Divides one Unsigned by an unscaled uint256, reverting on overflow or division by 0.

This will "floor" the quotient.

Parameters:#

  • a: a FixedPoint numerator.
  • b: a uint256 denominator.
div(uint256 a, struct FixedPoint.Unsigned b) โ†’ struct FixedPoint.Unsigned (internal)

Divides one unscaled uint256 by an Unsigned, reverting on overflow or division by 0.

This will "floor" the quotient.

Parameters:#

  • a: a uint256 numerator.
  • b: a FixedPoint denominator.
divCeil(struct FixedPoint.Unsigned a, struct FixedPoint.Unsigned b) โ†’ struct FixedPoint.Unsigned (internal)

Divides one Unsigned by an Unsigned and "ceil's" the quotient, reverting on overflow or division by 0.

Parameters:#

  • a: a FixedPoint numerator.
  • b: a FixedPoint denominator.
divCeil(struct FixedPoint.Unsigned a, uint256 b) โ†’ struct FixedPoint.Unsigned (internal)

Divides one Unsigned by an unscaled uint256 and "ceil's" the quotient, reverting on overflow or division by 0.

Parameters:#

  • a: a FixedPoint numerator.
  • b: a uint256 denominator.
pow(struct FixedPoint.Unsigned a, uint256 b) โ†’ struct FixedPoint.Unsigned output (internal)

Raises an Unsigned to the power of an unscaled uint256, reverting on overflow. E.g., b=2 squares a.

This will "floor" the result.

Parameters:#

  • a: a FixedPoint numerator.
  • b: a uint256 denominator.
fromSigned(struct FixedPoint.Signed a) โ†’ struct FixedPoint.Unsigned (internal)
fromUnsigned(struct FixedPoint.Unsigned a) โ†’ struct FixedPoint.Signed (internal)
fromUnscaledInt(int256 a) โ†’ struct FixedPoint.Signed (internal)

Constructs a Signed from an unscaled int, e.g., b=5 gets stored internally as 5*(10**18).

Parameters:#

  • a: int to convert into a FixedPoint.Signed.
isEqual(struct FixedPoint.Signed a, int256 b) โ†’ bool (internal)

Whether a is equal to b.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: a int256.
isEqual(struct FixedPoint.Signed a, struct FixedPoint.Signed b) โ†’ bool (internal)

Whether a is equal to b.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: a FixedPoint.Signed.
isGreaterThan(struct FixedPoint.Signed a, struct FixedPoint.Signed b) โ†’ bool (internal)

Whether a is greater than b.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: a FixedPoint.Signed.
isGreaterThan(struct FixedPoint.Signed a, int256 b) โ†’ bool (internal)

Whether a is greater than b.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: an int256.
isGreaterThan(int256 a, struct FixedPoint.Signed b) โ†’ bool (internal)

Whether a is greater than b.

Parameters:#

  • a: an int256.
  • b: a FixedPoint.Signed.
isGreaterThanOrEqual(struct FixedPoint.Signed a, struct FixedPoint.Signed b) โ†’ bool (internal)

Whether a is greater than or equal to b.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: a FixedPoint.Signed.
isGreaterThanOrEqual(struct FixedPoint.Signed a, int256 b) โ†’ bool (internal)

Whether a is greater than or equal to b.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: an int256.
isGreaterThanOrEqual(int256 a, struct FixedPoint.Signed b) โ†’ bool (internal)

Whether a is greater than or equal to b.

Parameters:#

  • a: an int256.
  • b: a FixedPoint.Signed.
isLessThan(struct FixedPoint.Signed a, struct FixedPoint.Signed b) โ†’ bool (internal)

Whether a is less than b.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: a FixedPoint.Signed.
isLessThan(struct FixedPoint.Signed a, int256 b) โ†’ bool (internal)

Whether a is less than b.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: an int256.
isLessThan(int256 a, struct FixedPoint.Signed b) โ†’ bool (internal)

Whether a is less than b.

Parameters:#

  • a: an int256.
  • b: a FixedPoint.Signed.
isLessThanOrEqual(struct FixedPoint.Signed a, struct FixedPoint.Signed b) โ†’ bool (internal)

Whether a is less than or equal to b.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: a FixedPoint.Signed.
isLessThanOrEqual(struct FixedPoint.Signed a, int256 b) โ†’ bool (internal)

Whether a is less than or equal to b.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: an int256.
isLessThanOrEqual(int256 a, struct FixedPoint.Signed b) โ†’ bool (internal)

Whether a is less than or equal to b.

Parameters:#

  • a: an int256.
  • b: a FixedPoint.Signed.
min(struct FixedPoint.Signed a, struct FixedPoint.Signed b) โ†’ struct FixedPoint.Signed (internal)

The minimum of a and b.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: a FixedPoint.Signed.
max(struct FixedPoint.Signed a, struct FixedPoint.Signed b) โ†’ struct FixedPoint.Signed (internal)

The maximum of a and b.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: a FixedPoint.Signed.
add(struct FixedPoint.Signed a, struct FixedPoint.Signed b) โ†’ struct FixedPoint.Signed (internal)

Adds two Signeds, reverting on overflow.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: a FixedPoint.Signed.
add(struct FixedPoint.Signed a, int256 b) โ†’ struct FixedPoint.Signed (internal)

Adds an Signed to an unscaled int, reverting on overflow.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: an int256.
sub(struct FixedPoint.Signed a, struct FixedPoint.Signed b) โ†’ struct FixedPoint.Signed (internal)

Subtracts two Signeds, reverting on overflow.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: a FixedPoint.Signed.
sub(struct FixedPoint.Signed a, int256 b) โ†’ struct FixedPoint.Signed (internal)

Subtracts an unscaled int256 from an Signed, reverting on overflow.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: an int256.
sub(int256 a, struct FixedPoint.Signed b) โ†’ struct FixedPoint.Signed (internal)

Subtracts an Signed from an unscaled int256, reverting on overflow.

Parameters:#

  • a: an int256.
  • b: a FixedPoint.Signed.
mul(struct FixedPoint.Signed a, struct FixedPoint.Signed b) โ†’ struct FixedPoint.Signed (internal)

Multiplies two Signeds, reverting on overflow.

This will "floor" the product.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: a FixedPoint.Signed.
mul(struct FixedPoint.Signed a, int256 b) โ†’ struct FixedPoint.Signed (internal)

Multiplies an Signed and an unscaled int256, reverting on overflow.

This will "floor" the product.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: an int256.
mulAwayFromZero(struct FixedPoint.Signed a, struct FixedPoint.Signed b) โ†’ struct FixedPoint.Signed (internal)

Multiplies two Signeds and "ceil's" the product, reverting on overflow.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: a FixedPoint.Signed.
mulAwayFromZero(struct FixedPoint.Signed a, int256 b) โ†’ struct FixedPoint.Signed (internal)

Multiplies an Signed and an unscaled int256 and "ceil's" the product, reverting on overflow.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: a FixedPoint.Signed.
div(struct FixedPoint.Signed a, struct FixedPoint.Signed b) โ†’ struct FixedPoint.Signed (internal)

Divides one Signed by an Signed, reverting on overflow or division by 0.

This will "floor" the quotient.

Parameters:#

  • a: a FixedPoint numerator.
  • b: a FixedPoint denominator.
div(struct FixedPoint.Signed a, int256 b) โ†’ struct FixedPoint.Signed (internal)

Divides one Signed by an unscaled int256, reverting on overflow or division by 0.

This will "floor" the quotient.

Parameters:#

  • a: a FixedPoint numerator.
  • b: an int256 denominator.
div(int256 a, struct FixedPoint.Signed b) โ†’ struct FixedPoint.Signed (internal)

Divides one unscaled int256 by an Signed, reverting on overflow or division by 0.

This will "floor" the quotient.

Parameters:#

  • a: an int256 numerator.
  • b: a FixedPoint denominator.
divAwayFromZero(struct FixedPoint.Signed a, struct FixedPoint.Signed b) โ†’ struct FixedPoint.Signed (internal)

Divides one Signed by an Signed and "ceil's" the quotient, reverting on overflow or division by 0.

Parameters:#

  • a: a FixedPoint numerator.
  • b: a FixedPoint denominator.
divAwayFromZero(struct FixedPoint.Signed a, int256 b) โ†’ struct FixedPoint.Signed (internal)

Divides one Signed by an unscaled int256 and "ceil's" the quotient, reverting on overflow or division by 0.

Parameters:#

  • a: a FixedPoint numerator.
  • b: an int256 denominator.
pow(struct FixedPoint.Signed a, uint256 b) โ†’ struct FixedPoint.Signed output (internal)

Raises an Signed to the power of an unscaled uint256, reverting on overflow. E.g., b=2 squares a.

This will "floor" the result.

Parameters:#

  • a: a FixedPoint.Signed.
  • b: a uint256 (negative exponents are not allowed).