pub struct AncDec128 { /* private fields */ }Expand description
128-bit fixed-point decimal (u128 int/frac, 38-digit precision, 40 bytes).
Stores integer and fractional parts as separate u128 values with an explicit scale (0-38).
§Example
use ancdec::AncDec128;
let a: AncDec128 = "123.456".parse().unwrap();
assert_eq!(a.int(), 123);Implementations§
Source§impl AncDec128
impl AncDec128
Sourcepub fn mul(&self, other: &Self) -> Self
pub fn mul(&self, other: &Self) -> Self
Multiplies two decimals, panics on overflow. Uses u256/u512 wide arithmetic when needed.
Sourcepub fn div(&self, other: &Self) -> Self
pub fn div(&self, other: &Self) -> Self
Divides self by other, panics on division by zero. Uses u256/u512 wide arithmetic when needed.
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 u128.
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 u128.
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 u128 integer range.
Source§impl AncDec128
impl AncDec128
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 AncDec128
impl AncDec128
Trait Implementations§
Source§impl AddAssign for AncDec128
impl AddAssign for AncDec128
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl DivAssign for AncDec128
impl DivAssign for AncDec128
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl From<AncDec> for AncDec128
Available on crate feature dec64 only.Lossless widening from AncDec (u64) to AncDec128 (u128)
impl From<AncDec> for AncDec128
dec64 only.Lossless widening from AncDec (u64) to AncDec128 (u128)
Source§impl From<AncDec32> for AncDec128
Available on crate feature dec32 only.Lossless widening from AncDec32 (u32) to AncDec128 (u128)
impl From<AncDec32> for AncDec128
dec32 only.Lossless widening from AncDec32 (u32) to AncDec128 (u128)
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 Hash for AncDec128
Normalizes trailing zeros so 1.0 == 1.00 have same hash
Uses u256 combined value via mul_wide
impl Hash for AncDec128
Normalizes trailing zeros so 1.0 == 1.00 have same hash Uses u256 combined value via mul_wide
Source§impl MulAssign for AncDec128
impl MulAssign for AncDec128
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl Ord for AncDec128
Ord trait
impl Ord for AncDec128
Ord trait
Source§impl PartialOrd for AncDec128
impl PartialOrd for AncDec128
Source§impl RemAssign for AncDec128
impl RemAssign for AncDec128
Source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%= operation. Read moreSource§impl SubAssign for AncDec128
impl SubAssign for AncDec128
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more