pub struct PreciseNumber {
pub val: U256,
}Expand description
Struct encapsulating a fixed-point number that allows for decimal calculations
Fields§
§val: U256Wrapper over the inner value, which is multiplied by ONE
Implementations§
Source§impl PreciseNumber
impl PreciseNumber
pub fn zero() -> Self
pub fn one() -> Self
Sourcepub fn new(val: u128) -> Result<Self>
pub fn new(val: u128) -> Result<Self>
Create a precise number from an imprecise u128, should always succeed
Sourcepub fn from_decimal(decimal: u128, exponent: i32) -> Result<Self>
pub fn from_decimal(decimal: u128, exponent: i32) -> Result<Self>
Create a precise number from a decimal number using exponent to adjust precision.
Sourcepub fn to_imprecise(&self) -> Result<u128>
pub fn to_imprecise(&self) -> Result<u128>
Convert a precise number back to u128
Sourcepub fn to_imprecise_u64(&self) -> Result<u64>
pub fn to_imprecise_u64(&self) -> Result<u64>
Convert a precise number back to u64
pub fn mul_up(self, rhs: Self) -> Result<Self>
pub fn div_up(self, rhs: Self) -> Result<Self>
Sourcepub fn almost_eq(&self, rhs: &Self, precision: U256) -> bool
pub fn almost_eq(&self, rhs: &Self, precision: U256) -> bool
Checks that two PreciseNumbers are equal within Ok tolerance
Sourcepub fn greater_than(&self, rhs: &Self) -> bool
pub fn greater_than(&self, rhs: &Self) -> bool
Checks that a number is greater than another
Sourcepub fn less_than_or_equal(&self, rhs: &Self) -> bool
pub fn less_than_or_equal(&self, rhs: &Self) -> bool
Checks that a number is less than another
Sourcepub fn greater_than_or_equal(&self, rhs: &Self) -> bool
pub fn greater_than_or_equal(&self, rhs: &Self) -> bool
Checks that a number is greater than another
Sourcepub fn checked_div(&self, rhs: &Self) -> Result<Self>
pub fn checked_div(&self, rhs: &Self) -> Result<Self>
Performs a checked division on two precise numbers
Sourcepub fn checked_mul(&self, rhs: &Self) -> Result<Self>
pub fn checked_mul(&self, rhs: &Self) -> Result<Self>
Performs a multiplication on two precise numbers
Sourcepub fn checked_add(&self, rhs: &Self) -> Result<Self>
pub fn checked_add(&self, rhs: &Self) -> Result<Self>
Performs addition of two precise numbers
Sourcepub fn checked_sub(&self, rhs: &Self) -> Result<Self>
pub fn checked_sub(&self, rhs: &Self) -> Result<Self>
Subtracts the argument from self
Sourcepub fn unsigned_sub(&self, rhs: &Self) -> (Self, bool)
pub fn unsigned_sub(&self, rhs: &Self) -> (Self, bool)
Performs a subtraction, returning the result and whether the result is negative
Sourcepub fn checked_pow(&self, exponent: u128) -> Result<Self>
pub fn checked_pow(&self, exponent: u128) -> Result<Self>
Performs pow on a precise number
Trait Implementations§
Source§impl Add for PreciseNumber
impl Add for PreciseNumber
Source§type Output = PreciseNumber
type Output = PreciseNumber
+ operator.Source§impl AddAssign for PreciseNumber
impl AddAssign for PreciseNumber
Source§fn add_assign(&mut self, rhs: PreciseNumber)
fn add_assign(&mut self, rhs: PreciseNumber)
+= operation. Read moreSource§impl Clone for PreciseNumber
impl Clone for PreciseNumber
Source§fn clone(&self) -> PreciseNumber
fn clone(&self) -> PreciseNumber
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PreciseNumber
impl Debug for PreciseNumber
Source§impl Default for PreciseNumber
impl Default for PreciseNumber
Source§fn default() -> PreciseNumber
fn default() -> PreciseNumber
Source§impl Div for PreciseNumber
impl Div for PreciseNumber
Source§type Output = PreciseNumber
type Output = PreciseNumber
/ operator.Source§impl DivAssign for PreciseNumber
impl DivAssign for PreciseNumber
Source§fn div_assign(&mut self, rhs: PreciseNumber)
fn div_assign(&mut self, rhs: PreciseNumber)
/= operation. Read moreSource§impl Mul for PreciseNumber
impl Mul for PreciseNumber
Source§type Output = PreciseNumber
type Output = PreciseNumber
* operator.Source§impl MulAssign for PreciseNumber
impl MulAssign for PreciseNumber
Source§fn mul_assign(&mut self, rhs: PreciseNumber)
fn mul_assign(&mut self, rhs: PreciseNumber)
*= operation. Read moreSource§impl Ord for PreciseNumber
impl Ord for PreciseNumber
Source§fn cmp(&self, other: &PreciseNumber) -> Ordering
fn cmp(&self, other: &PreciseNumber) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for PreciseNumber
impl PartialEq for PreciseNumber
Source§impl PartialOrd for PreciseNumber
impl PartialOrd for PreciseNumber
Source§impl Sub for PreciseNumber
impl Sub for PreciseNumber
Source§type Output = PreciseNumber
type Output = PreciseNumber
- operator.Source§impl SubAssign for PreciseNumber
impl SubAssign for PreciseNumber
Source§fn sub_assign(&mut self, rhs: PreciseNumber)
fn sub_assign(&mut self, rhs: PreciseNumber)
-= operation. Read moreimpl Copy for PreciseNumber
impl Eq for PreciseNumber
impl StructuralPartialEq for PreciseNumber
Auto Trait Implementations§
impl Freeze for PreciseNumber
impl RefUnwindSafe for PreciseNumber
impl Send for PreciseNumber
impl Sync for PreciseNumber
impl Unpin for PreciseNumber
impl UnwindSafe for PreciseNumber
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more