pub struct PreciseNumber {
pub value: U256,
}
Expand description
Struct encapsulating a fixed-point number that allows for decimal calculations
Fields§
§value: U256
Wrapper over the inner value, which is multiplied by ONE
Implementations§
Source§impl PreciseNumber
impl PreciseNumber
Sourcepub fn new(value: u128) -> Option<Self>
pub fn new(value: u128) -> Option<Self>
Create a precise number from an imprecise u128, should always succeed
Sourcepub fn to_imprecise(&self) -> Option<u128>
pub fn to_imprecise(&self) -> Option<u128>
Convert a precise number back to u128
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 some 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) -> Option<Self>
pub fn checked_div(&self, rhs: &Self) -> Option<Self>
Performs a checked division on two precise numbers
Sourcepub fn checked_mul(&self, rhs: &Self) -> Option<Self>
pub fn checked_mul(&self, rhs: &Self) -> Option<Self>
Performs a multiplication on two precise numbers
Sourcepub fn checked_add(&self, rhs: &Self) -> Option<Self>
pub fn checked_add(&self, rhs: &Self) -> Option<Self>
Performs addition of two precise numbers
Sourcepub fn checked_sub(&self, rhs: &Self) -> Option<Self>
pub fn checked_sub(&self, rhs: &Self) -> Option<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) -> Option<Self>
pub fn checked_pow(&self, exponent: u128) -> Option<Self>
Performs pow on a precise number
Trait Implementations§
Source§impl Clone for PreciseNumber
impl Clone for PreciseNumber
Source§fn clone(&self) -> PreciseNumber
fn clone(&self) -> PreciseNumber
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for PreciseNumber
impl Debug for PreciseNumber
Source§impl PartialEq for PreciseNumber
impl PartialEq 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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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