addition: reciprocal, abs, is zero and is int

This commit is contained in:
2026-04-27 17:48:57 -06:00
parent 65cb25cdfd
commit 11d739e523

View File

@@ -33,24 +33,28 @@ impl Fraction {
let mut new = Fraction { num, den }; let mut new = Fraction { num, den };
new.reduce(); new.reduce();
new.correct_sign();
Ok(new) Ok(new)
} }
pub fn reciprocal(&self) -> Result<Self, FractionError> { pub fn reciprocal(&self) -> Result<Self, FractionError> {
todo!() Fraction::new(self.den, self.num)
} }
pub fn abs(&self) -> Self { pub fn abs(&self) -> Self {
todo!() Fraction {
num: self.num.abs(),
den: self.den,
}
} }
pub fn is_zero(&self) -> bool { pub fn is_zero(&self) -> bool {
todo!() self.num == 0
} }
pub fn is_integer(&self) -> bool { pub fn is_integer(&self) -> bool {
todo!() self.den == 1
} }
fn gcd(a: i64, b: i64) -> i64 { fn gcd(a: i64, b: i64) -> i64 {