|
|
|
@ -28,6 +28,8 @@ use std::fmt::{Formatter, Display}; |
|
|
|
use std::num::TryFromIntError;
|
|
|
|
use std::ops::{Add,Sub,Neg,Mul,Div};
|
|
|
|
|
|
|
|
use crate::continuous::Continuous;
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, Clone, Copy)]
|
|
|
|
pub struct Fractional (pub i64, pub i64);
|
|
|
|
|
|
|
|
@ -67,8 +69,27 @@ impl Fractional { |
|
|
|
Self(1, _n / _d)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Self(n / hcf(n, d), d / hcf(n, d))
|
|
|
|
//Self(n / hcf(n, d), d / hcf(n, d))
|
|
|
|
let regular_reduced = self;
|
|
|
|
let cont :Continuous = (®ular_reduced).into();
|
|
|
|
cont.into_prec(5)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn noreduce_add(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))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn noreduce_sub(self, other: Self) -> Self {
|
|
|
|
self.noreduce_add(other.noreduce_neg())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn noreduce_neg(self) -> Self {
|
|
|
|
let Fractional(n, d) = self;
|
|
|
|
Self(-n, d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|