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_downandmul_div_upviaU512.
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§
Macros§
- fixed
- Creates a
FixedPoint<T>from a decimal number. Infers the type ofTfrom 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
FixedPointValueand 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§
- Fixed
Point - A generic fixed point type built on ethers-rs.
- Uniform
Fixed Point
Enums§
- Fixed
Point Sign - The sign associated with a fixed point number.
Traits§
- Fixed
- A
FixedPointValuethat can convert toFixedPoint<Self>via.fixed(). - Fixed
Point Value - 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 toFixedPoint<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.