fix reducer sign error

This commit is contained in:
hugogogo
2026-05-15 01:03:14 +02:00
parent 7e16bb5b6f
commit b185647d2b
5 changed files with 25 additions and 22 deletions

View File

@@ -1,9 +1,5 @@
# 42_EXT_05_computorv1
## todo
- double is nearly_equal_0
## ressources

View File

@@ -191,7 +191,7 @@ void solve(const s_polynom *polynom, s_solution *solution);
*/
void print_reduced_form(s_polynom *polynom, int degree);
void print_degree(s_polynom *polynom, int max_exponent);
void print_degree(s_polynom *polynom, int degree);
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* PRINTER_SOLUTIONS.C

View File

@@ -21,7 +21,8 @@ static double get_all_terms_with_exponent(s_term *terms, int exponent)
// sign
sign = 1;
if (terms[i].position == TERM_RIGHT)
sign = terms[i].sign == TERM_PLUS ? -1 : 1;
sign = -1;
// sign = terms[i].sign == TERM_PLUS ? -1 : 1;
// add coefficients
coefficient += terms[i].coefficient * sign;

View File

@@ -14,7 +14,7 @@ static void solve_degree_1(s_solution_degree_1 *solution, double a, double b)
solution->a = a;
solution->b = b;
solution->solution = positiv_zero(-b / a); // -b / a
solution->solution = positiv_zero(-b / a);
}
static void solve_degree_2(s_solution_degree_2 *solution, double a, double b, double c)

View File

@@ -233,11 +233,11 @@ Discriminant is strictly negative, the two complex solutions are:
run_test \
"13. degree 2" \
"3x² + 0x -7 = x" "\
Reduced form: 7 * x^0 - 1 * x^1 + 3 * x^2 = 0
Reduced form: -7 * x^0 - 1 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Discriminant is strictly negative, the two complex solutions are:
1/6 + 9.11043i/6
1/6 - 9.11043i/6"
Discriminant is strictly positive, the two solutions are:
1.369924
-1.369924"
run_test \
"14. degree 2" \
@@ -270,7 +270,7 @@ run_test \
"3x² + x -0 = x" "\
Reduced form: 0 * x^0 + 0 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Discriminant is equal to zero, the solution is:
Radicant is equal to zero, the solution is:
0"
run_test \
@@ -282,14 +282,14 @@ Any real number is a solution."
run_test \
"19. degree 5" \
"2x⁵ + x -0 = -7x^5" "\
Reduced form: 0 * x^0 + 1 * x^1 + 0 * x^2 + 0 * x^3 + 0 * x^4 - 5 * x^5 = 0
Reduced form: 0 * x^0 + 1 * x^1 + 0 * x^2 + 0 * x^3 + 0 * x^4 + 9 * x^5 = 0
Polynomial degree: 5
The polynomial degree is strictly greater than 2, I can't solve."
run_test \
"20. degree 1" \
"2x + x -0 = -7x" "\
Reduced form: 0 * x^0 - 4 * x^1 = 0
Reduced form: 0 * x^0 + 10 * x^1 = 0
Polynomial degree: 1
The solution is:
0"
@@ -297,10 +297,18 @@ The solution is:
run_test \
"21. degree 1" \
"2x + x -3 = -7x" "\
Reduced form: 3 * x^0 - 4 * x^1 = 0
Reduced form: -3 * x^0 + 10 * x^1 = 0
Polynomial degree: 1
The solution is:
0.75"
0.3"
run_test \
"22. degree 1" \
"-2x + x -3 = -7x" "\
Reduced form: -3 * x^0 + 6 * x^1 = 0
Polynomial degree: 1
The solution is:
0.5"
run_test \
"23. degree 2 without [=]" \
@@ -313,7 +321,7 @@ run_test \
"3x^2 = 0" "\
Reduced form: 0 * x^0 + 0 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Discriminant is equal to zero, the solution is:
Radicant is equal to zero, the solution is:
0"
run_test \
@@ -321,9 +329,9 @@ run_test \
"3x^2 + 2 = 0" "\
Reduced form: 2 * x^0 + 0 * x^1 + 3 * x^2 = 0
Polynomial degree: 2
Discriminant is strictly negative, the two complex solutions are:
4.89898i/6
-4.89898i/6"
Radicant is strictly negative, the two complex solutions are:
i√(2/3)
-i√(2/3)"
run_test \
"26. degree 2 pure" \
@@ -352,7 +360,6 @@ Radicant is strictly positive, the two solutions are:
2/√(3)
-2/√(3)"
run_test \
"29. degree 2 pure" \
"16 * x^2 + 5 * x^1 - 4 * x^0 = 5 * x" "\
@@ -362,7 +369,6 @@ Radicant is strictly positive, the two solutions are:
1/2
-1/2"
run_test \
"30. degree 2 pure" \
"4 * x^2 + 5 * x^1 - 16 * x^0 = 5 * x" "\