pub struct AncDec8 { /* private fields */ }Expand description
8-bit fixed-point decimal (u8 int/frac, 2-digit precision, 4 bytes).
Stores integer and fractional parts as separate u8 values with an explicit scale (0-2).
§Example
use ancdec::AncDec8;
let a: AncDec8 = "1.23".parse().unwrap();
assert_eq!(a.int(), 1);Implementations§
Source§impl AncDec8
impl AncDec8
Sourcepub fn checked_add(&self, other: &Self) -> Option<Self>
pub fn checked_add(&self, other: &Self) -> Option<Self>
Checked addition. Returns None if the integer part overflows u8.
Sourcepub fn checked_sub(&self, other: &Self) -> Option<Self>
pub fn checked_sub(&self, other: &Self) -> Option<Self>
Checked subtraction. Returns None if the integer part overflows u8.
In practice, subtraction in the current design uses magnitude comparison
and cannot overflow, so this always returns Some.
Sourcepub fn checked_mul(&self, other: &Self) -> Option<Self>
pub fn checked_mul(&self, other: &Self) -> Option<Self>
Checked multiplication. Returns None if the result overflows u8 integer range.
Source§impl AncDec8
impl AncDec8
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Returns true if the value is strictly positive.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Returns true if the value is strictly negative.
Source§impl AncDec8
impl AncDec8
Trait Implementations§
Source§impl AddAssign for AncDec8
impl AddAssign for AncDec8
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl DivAssign for AncDec8
impl DivAssign for AncDec8
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl From<AncDec8> for AncDec
Available on crate feature dec8 only.Lossless widening from AncDec8 (u8) to AncDec (u64)
impl From<AncDec8> for AncDec
dec8 only.Lossless widening from AncDec8 (u8) to AncDec (u64)
Source§impl From<AncDec8> for AncDec128
Available on crate feature dec8 only.Lossless widening from AncDec8 (u8) to AncDec128 (u128)
impl From<AncDec8> for AncDec128
dec8 only.Lossless widening from AncDec8 (u8) to AncDec128 (u128)
Source§impl From<AncDec8> for AncDec32
Available on crate feature dec8 only.Lossless widening from AncDec8 (u8) to AncDec32 (u32)
impl From<AncDec8> for AncDec32
dec8 only.Lossless widening from AncDec8 (u8) to AncDec32 (u32)
Source§impl Hash for AncDec8
Normalizes trailing zeros so 1.0 == 1.00 have same hash
Uses u16 combined value
impl Hash for AncDec8
Normalizes trailing zeros so 1.0 == 1.00 have same hash Uses u16 combined value
Source§impl MulAssign for AncDec8
impl MulAssign for AncDec8
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl Ord for AncDec8
Ord trait
impl Ord for AncDec8
Ord trait
Source§impl PartialOrd for AncDec8
impl PartialOrd for AncDec8
Source§impl RemAssign for AncDec8
impl RemAssign for AncDec8
Source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%= operation. Read moreSource§impl SubAssign for AncDec8
impl SubAssign for AncDec8
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more