clean(*): prep 42

This commit is contained in:
gbrochar 2023-11-22 19:35:06 +01:00
parent 8260e7fc92
commit 0628e54d6e
3 changed files with 1 additions and 35 deletions

View File

@ -94,7 +94,6 @@ fn solve_degree_2(equation: Vec<f64>) {
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<f64>) {
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
}
}

View File

@ -43,7 +43,6 @@ fn get_prime_factors(mut n: i128) -> Vec<i128> {
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,
}*/
}

View File

@ -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);
}