#[repr(transparent)]pub struct Decimal<I, const D: u8>(pub I);Tuple Fields§
§0: IImplementations§
Source§impl<I, const D: u8> Decimal<I, D>where
I: ScaledInteger<D>,
impl<I, const D: u8> Decimal<I, D>where
I: ScaledInteger<D>,
Source§impl<I, const D: u8> Decimal<I, D>where
I: ScaledInteger<D>,
impl<I, const D: u8> Decimal<I, D>where
I: ScaledInteger<D>,
pub const ZERO: Decimal<I, D>
pub const ONE: Decimal<I, D>
pub const TWO: Decimal<I, D>
pub const MIN: Decimal<I, D>
pub const MAX: Decimal<I, D>
pub const DECIMALS: u8 = D
pub const SCALING_FACTOR: I = I::SCALING_FACTOR
pub const fn min() -> Self
👎Deprecated:
use Self::MIN
pub const fn max() -> Self
👎Deprecated:
use Self::MAX
Sourcepub fn try_from_scaled(integer: I, scale: u8) -> Option<Self>
pub fn try_from_scaled(integer: I, scale: u8) -> Option<Self>
Losslessly converts a scaled integer to this type.
§Examples
use const_decimal::Decimal;
let five = Decimal::<u64, 3>::try_from_scaled(5, 0).unwrap();
assert_eq!(five, Decimal::TWO + Decimal::TWO + Decimal::ONE);
assert_eq!(five.0, 5000);pub fn is_zero(&self) -> bool
Sourcepub fn quantize_round_to_zero(&self, quantum: Self) -> Self
pub fn quantize_round_to_zero(&self, quantum: Self) -> Self
Round a number to a multiple of a given quantum toward zero.
general ref: https://en.wikipedia.org/wiki/Quantization_(signal_processing)
By default, rust is rounding towards zero and so does this method.
§Example:
use const_decimal::Decimal;
// 11.65
let d = Decimal::<i64, 5>::try_from_scaled(1165, 2).unwrap();
// Allow only increments of 0.5
let quantum = Decimal::<i64, 5>::try_from_scaled(5, 1).unwrap();
let q = d.quantize_round_to_zero(quantum);
// 11.5 rounded down to the nearest `quantum`.
assert_eq!(q, Decimal::try_from_scaled(115, 1).unwrap());Trait Implementations§
Source§impl<I, const D: u8> AddAssign for Decimal<I, D>where
I: ScaledInteger<D>,
impl<I, const D: u8> AddAssign for Decimal<I, D>where
I: ScaledInteger<D>,
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+= operation. Read moreimpl<I: Copy, const D: u8> Copy for Decimal<I, D>
Source§impl<I, const D: u8> DivAssign for Decimal<I, D>where
I: ScaledInteger<D>,
impl<I, const D: u8> DivAssign for Decimal<I, D>where
I: ScaledInteger<D>,
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
Performs the
/= operation. Read moreimpl<I: Eq, const D: u8> Eq for Decimal<I, D>
Source§impl<I, const D: u8> MulAssign for Decimal<I, D>where
I: ScaledInteger<D>,
impl<I, const D: u8> MulAssign for Decimal<I, D>where
I: ScaledInteger<D>,
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the
*= operation. Read moreSource§impl<I, const D: u8> Num for Decimal<I, D>where
I: SignedScaledInteger<D>,
impl<I, const D: u8> Num for Decimal<I, D>where
I: SignedScaledInteger<D>,
type FromStrRadixErr = ParseDecimalError<I>
Source§fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
Convert from a string and radix (typically
2..=36). Read moreSource§impl<I: Ord, const D: u8> Ord for Decimal<I, D>
impl<I: Ord, const D: u8> Ord for Decimal<I, D>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<I: PartialOrd, const D: u8> PartialOrd for Decimal<I, D>
impl<I: PartialOrd, const D: u8> PartialOrd for Decimal<I, D>
Source§impl<I, const D: u8> Signed for Decimal<I, D>where
I: SignedScaledInteger<D>,
impl<I, const D: u8> Signed for Decimal<I, D>where
I: SignedScaledInteger<D>,
Source§fn is_positive(&self) -> bool
fn is_positive(&self) -> bool
Returns true if the number is positive and false if the number is zero or negative.
Source§fn is_negative(&self) -> bool
fn is_negative(&self) -> bool
Returns true if the number is negative and false if the number is zero or positive.
impl<I: PartialEq, const D: u8> StructuralPartialEq for Decimal<I, D>
Source§impl<I, const D: u8> SubAssign for Decimal<I, D>where
I: ScaledInteger<D>,
impl<I, const D: u8> SubAssign for Decimal<I, D>where
I: ScaledInteger<D>,
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-= operation. Read moreAuto Trait Implementations§
impl<I, const D: u8> Freeze for Decimal<I, D>where
I: Freeze,
impl<I, const D: u8> RefUnwindSafe for Decimal<I, D>where
I: RefUnwindSafe,
impl<I, const D: u8> Send for Decimal<I, D>where
I: Send,
impl<I, const D: u8> Sync for Decimal<I, D>where
I: Sync,
impl<I, const D: u8> Unpin for Decimal<I, D>where
I: Unpin,
impl<I, const D: u8> UnsafeUnpin for Decimal<I, D>where
I: UnsafeUnpin,
impl<I, const D: u8> UnwindSafe for Decimal<I, D>where
I: UnwindSafe,
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