Struct spl_math::precise_number::PreciseNumber
source · pub struct PreciseNumber {
pub value: U256,
}Expand description
Struct encapsulating a fixed-point number that allows for decimal calculations
Fields§
§value: U256Wrapper 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 copy 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
source§fn eq(&self, other: &PreciseNumber) -> bool
fn eq(&self, other: &PreciseNumber) -> bool
This method tests for
self and other values to be equal, and is used
by ==.impl StructuralPartialEq for PreciseNumber
Auto Trait Implementations§
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