Crate fixedpointmath

Source
Expand description

A generic fixed point wrapper around the U256 type from ethers-rs.

The math in this library is a heavily based on Solidity’s FixedPointMath library with a few changes:

  • The outward type of the underlying value is generic, allowing the library to be used with any type that implements FixedPointValue, including signed integers, and ensuring that the instance is bounded by the generic type’s limits.
  • Support for overflowing intermediate operations in mul_div_down and mul_div_up via U512.

Each of the functions is fuzz tested against the Solidity implementation to ensure that the behavior is identical given values bounded by the Solidity implementation’s limits.

Modules§

prelude

Macros§

fixed
Creates a FixedPoint<T> from a decimal number. Infers the type of T from the context. If the context is ambiguous, use a typed alternative such as [fixed_u256!] or [fixed_i256!].
fixed_i128
Creates a FixedPoint<i128> from a decimal number.
fixed_i256
Creates a FixedPoint<I256> from a decimal number.
fixed_point_value_impl
Implements FixedPointValue and conversion traits for the given type.
fixed_u128
Creates a FixedPoint<u128> from a decimal number.
fixed_u256
Creates a FixedPoint<U256> from a decimal number.
int256
uint256

Structs§

FixedPoint
A generic fixed point type built on ethers-rs.
UniformFixedPoint

Enums§

FixedPointSign
The sign associated with a fixed point number.

Traits§

Fixed
A FixedPointValue that can convert to FixedPoint<Self> via .fixed().
FixedPointValue
A value that can be used to perform fixed-point math.
ToFixed
A type that can convert to FixedPoint<T> via .to_fixed(), and attempt conversion to FixedPoint<T> via .try_to_fixed().

Functions§

exp
Math
i256_from_str
Parse a string into an I256 with support for scientific and decimal notation.
ln
u256_from_str
Parses a string into a U256 with support for scientific and decimal notation.