|
|
|
@ -129,7 +129,11 @@ impl Fractional { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inner(1, x / 2, x)
|
|
|
|
match x {
|
|
|
|
0 => 0.into(),
|
|
|
|
1 => 1.into(),
|
|
|
|
_ => inner(1, x / 2, x),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let Fractional(n, d) = self;
|
|
|
|
@ -141,7 +145,7 @@ impl Fractional { |
|
|
|
};
|
|
|
|
|
|
|
|
let d = match d.cmp(&0) {
|
|
|
|
Ordering::Equal => return Err("division by zero"),
|
|
|
|
Ordering::Equal => 0.into(),
|
|
|
|
Ordering::Less => return Err("sqrt on negative undefined"),
|
|
|
|
Ordering::Greater => floor_sqrt(d),
|
|
|
|
};
|
|
|
|
@ -268,10 +272,7 @@ impl Sub for Fractional { |
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn sub(self, other: Self) -> Self {
|
|
|
|
let Fractional(n1, d1) = self;
|
|
|
|
let Fractional(n2, d2) = other;
|
|
|
|
let n = n1 * (self.gcd(other) / d1) - n2 * (self.gcd(other) / d2);
|
|
|
|
Self(n, self.gcd(other)).reduce()
|
|
|
|
self + -other
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|