fix(maths::solver): simplify_sqrt
Last prime factor now always in array, the bug was that if the last prime factor is bigger that sqrt(n) it wasn't pushed since the loop escaped
This commit is contained in:
parent
4068b3a3cd
commit
6fb0c2480f
|
@ -63,8 +63,12 @@ fn simplify_sqrt(mut n: i128) -> (i128, i128) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if n != 1 {
|
||||
prime_factors.push(n);
|
||||
}
|
||||
let (mut natural, mut irrational) = (1, 1);
|
||||
prime_factors = prime_factors.into_iter().rev().collect();
|
||||
dbg!(&prime_factors);
|
||||
while prime_factors.len() > 1 {
|
||||
let pop = prime_factors.pop().unwrap();
|
||||
if *prime_factors.last().unwrap() == pop {
|
||||
|
@ -307,7 +311,11 @@ fn degree_two_complex(a: GaussianRational, b: GaussianRational, c: GaussianRatio
|
|||
|
||||
fn sqrt(n: Rational, a: Rational) -> MySqrt {
|
||||
let numerator_irrational = n.numerator * n.denominator;
|
||||
dbg!(numerator_irrational);
|
||||
let (mut numerator_natural, numerator_irrational) = simplify_sqrt(numerator_irrational);
|
||||
dbg!(numerator_natural);
|
||||
dbg!(numerator_irrational);
|
||||
|
||||
numerator_natural *= a.denominator;
|
||||
let mut denominator = n.denominator * 2 * a.numerator;
|
||||
let gcd = gcd(numerator_natural, denominator);
|
||||
|
@ -401,6 +409,9 @@ fn degree_two_real(a: Rational, b: Rational, c: Rational) {
|
|||
let mut sqrt_delta = sqrt(delta, a);
|
||||
let mut left_part = (-1 * b) / (2 * a);
|
||||
|
||||
println!("sqrt delta {:?}", sqrt_delta);
|
||||
println!("left part {:?}", left_part);
|
||||
|
||||
let tmp = left_part.denominator;
|
||||
|
||||
left_part.denominator *= sqrt_delta.denominator;
|
||||
|
@ -408,7 +419,7 @@ fn degree_two_real(a: Rational, b: Rational, c: Rational) {
|
|||
|
||||
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;
|
||||
|
@ -416,7 +427,7 @@ fn degree_two_real(a: Rational, b: Rational, c: Rational) {
|
|||
|
||||
sqrt_delta.numerator_natural /= gcd;
|
||||
sqrt_delta.denominator /= gcd;
|
||||
|
||||
*/
|
||||
print_degree_two_real(left_part, sqrt_delta, imaginary);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue