From 0628e54d6e4d079f6c62d86ee84b9ce8e84ac534 Mon Sep 17 00:00:00 2001 From: gbrochar Date: Wed, 22 Nov 2023 19:35:06 +0100 Subject: [PATCH] clean(*): prep 42 --- src/lib.rs | 3 --- src/maths.rs | 24 +----------------------- src/maths/solver.rs | 9 --------- 3 files changed, 1 insertion(+), 35 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1aaa5c7..090d6a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,7 +94,6 @@ fn solve_degree_2(equation: Vec) { println!("Discriminant is strictly positive, the two solutions are:"); println!("{x1}"); println!("{x2}"); - //(-b +- sqrt(delta)) / 2a } else if delta < 0. { let sqrt_delta = sqrt(delta); let a = -equation[1] / (2. * equation[2]); @@ -102,12 +101,10 @@ fn solve_degree_2(equation: Vec) { println!("Discriminant is strictly negative, the two complex solutions are:"); println!("{a} + {b}i"); println!("{a} - {b}i"); - //(-b +- i sqrt(-delta)) / 2a } else { let x = -equation[1] / (2. * equation[2]); println!("Discriminant is zero, the solution is:"); println!("{x}"); - //-b / 2a } } diff --git a/src/maths.rs b/src/maths.rs index 7fd1179..9cfb8dc 100644 --- a/src/maths.rs +++ b/src/maths.rs @@ -43,7 +43,6 @@ fn get_prime_factors(mut n: i128) -> Vec { prime_factors } -//TODO slow ? check Stein's algorithm (binaryGCD) + tests fn gcd(a: i128, b: i128) -> i128 { if b == 0 { a @@ -86,7 +85,6 @@ impl Rational { fn format_fract(&self) -> String { let mut copy = self.clone(); let factors = get_prime_factors(self.denominator); - dbg!(&factors); let mut two_count = 0; let mut five_count = 0; for factor in factors { @@ -111,7 +109,6 @@ impl Rational { format!("{}.{}", copy.numerator / copy.denominator, copy.numerator % copy.denominator) } - // TODO return string pub fn format(&self) -> String { match (self.numerator, self.denominator) { (_, 1) => format!("{}", self.numerator), @@ -119,7 +116,6 @@ impl Rational { } } - // TODO rename or move to better scope, only used in complex div ? pub fn simplify(lhs: Rational, rhs: Rational) -> Self { let res = Rational::new(lhs.numerator * rhs.denominator, lhs.denominator * rhs.numerator); res.reduce() @@ -253,7 +249,6 @@ impl GaussianRational { GaussianRational::new(self.real, -1 * self.imaginary) } - // TODO return string, avoid printing real or imag part if zero pub fn format(&self) -> String { match (self.real().is_zero(), self.imaginary.is_zero()) { (true, true) => format!(""), @@ -394,7 +389,6 @@ mod tests { assert_eq!(rational.left_shift(), Rational::new(7, 30)); } - // TODO #[test] fn simplify() { let a = Rational::new(10, 3); @@ -523,20 +517,4 @@ mod tests { assert_eq!(n * a, GaussianRational::new(Rational::new(15, 7), Rational::new(8, 1))); } } -} - -/* -pub struct SquareRoot { - rational: Rational, - irrational: Rational, -} - -pub struct Algebraic { - rational: Rational, - algebraic: SquareRoot, -} - -pub struct GaussianAlgebraic { - real: Algebraic, - imaginary: Algebraic, -}*/ \ No newline at end of file +} \ No newline at end of file diff --git a/src/maths/solver.rs b/src/maths/solver.rs index 75dd66a..bfb93de 100644 --- a/src/maths/solver.rs +++ b/src/maths/solver.rs @@ -341,18 +341,9 @@ fn degree_two_real(a: Rational, b: Rational, c: Rational) { left_part.denominator *= sqrt_delta.denominator; left_part.numerator *= sqrt_delta.denominator; - sqrt_delta.numerator_natural *= tmp; sqrt_delta.denominator *= tmp; -/* - let gcd = gcd(gcd(sqrt_delta.numerator_natural, left_part.numerator), left_part.denominator); - left_part.denominator /= gcd; - left_part.numerator /= gcd; - - sqrt_delta.numerator_natural /= gcd; - sqrt_delta.denominator /= gcd; -*/ print_degree_two_real(left_part, sqrt_delta, imaginary); }