pub struct Fraction {
pub numerator: u64,
pub denominator: u64,
}Expand description
Exact rational number for weighted threshold arithmetic.
Uses integer cross-multiplication for comparison — NOT floating point.
This ensures 1/3 + 1/3 + 1/3 equals exactly 1.
Usage:
use auths_keri::Fraction;
let f: Fraction = "1/3".parse().unwrap();
assert_eq!(f.numerator, 1);
assert_eq!(f.denominator, 3);Fields§
§numerator: u64Numerator of the fraction.
denominator: u64Denominator of the fraction (must be > 0).
Implementations§
Source§impl Fraction
impl Fraction
Sourcepub fn sum_meets_one(fractions: &[&Fraction]) -> bool
pub fn sum_meets_one(fractions: &[&Fraction]) -> bool
Check if the sum of the given fractions is >= 1, using exact integer arithmetic.
Uses cross-multiplication to avoid floating-point imprecision.
1/3 + 1/3 + 1/3 returns true (exactly 1).
Usage:
use auths_keri::Fraction;
let thirds: Vec<Fraction> = vec!["1/3".parse().unwrap(); 3];
let refs: Vec<&Fraction> = thirds.iter().collect();
assert!(Fraction::sum_meets_one(&refs));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Fraction
impl<'de> Deserialize<'de> for Fraction
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Fraction
impl StructuralPartialEq for Fraction
Auto Trait Implementations§
impl Freeze for Fraction
impl RefUnwindSafe for Fraction
impl Send for Fraction
impl Sync for Fraction
impl Unpin for Fraction
impl UnsafeUnpin for Fraction
impl UnwindSafe for Fraction
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.