From 11d739e5231874202e03116f22a61bb74a93ae47 Mon Sep 17 00:00:00 2001 From: laentropia Date: Mon, 27 Apr 2026 17:48:57 -0600 Subject: [PATCH] addition: reciprocal, abs, is zero and is int --- src/lib.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fecfa75..de7e3af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,24 +33,28 @@ impl Fraction { let mut new = Fraction { num, den }; new.reduce(); + new.correct_sign(); Ok(new) } pub fn reciprocal(&self) -> Result { - todo!() + Fraction::new(self.den, self.num) } pub fn abs(&self) -> Self { - todo!() + Fraction { + num: self.num.abs(), + den: self.den, + } } pub fn is_zero(&self) -> bool { - todo!() + self.num == 0 } pub fn is_integer(&self) -> bool { - todo!() + self.den == 1 } fn gcd(a: i64, b: i64) -> i64 {