addition: reciprocal, abs, is zero and is int
This commit is contained in:
12
src/lib.rs
12
src/lib.rs
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user