wip implemented new union for solve

This commit is contained in:
hugogogo
2026-05-08 01:00:03 +02:00
parent 0fcfd0260d
commit 43b4def6ce
9 changed files with 176 additions and 105 deletions

View File

@@ -69,32 +69,43 @@ static int find_gcd(double numerator, double denominator)
}
/*
e_delta_sign delta_sign; // DELTA_PLUS or DELTA_MINUS or DELTA_ZERO
double delta_absolute; // |Δ| == |b² - 4ac|
int first_term_gcd; // gcd(b, 2a)
int first_term_numerator; // -b / gcd
int first_term_denominator; // 2a / gcd
double first_term; // double (-b / 2a)
int second_term_gcd; // gcd(√|Δ|, 2a)
int second_term_numerator; // √|Δ| / gcd
int second_term_denominator; // 2a / gcd
double second_term; // double (√|Δ| / 2a)
double solution1; // first_term + second_term
double solution2; // first_term - second_term
typedef struct
{
double a; // a in "ax + b"
double b; // b in "ax + b"
int solution_gcd; // gcd(b, a)
int solution_numerator; // -b / gcd
int solution_denominator; // a / gcd
double solution; // double (-b / a)
} s_solution_degree_1;
*/
/*
typedef struct
{
double a; // a in "ax² + bx + c"
double b; // b in "ax² + bx + c"
double c; // c in "ax² + bx + c"
e_delta_sign delta_sign; // DELTA_PLUS or DELTA_MINUS or DELTA_ZERO
double delta_absolute; // |Δ| == |b² - 4ac|
int first_term_gcd; // gcd(b, 2a)
int first_term_numerator; // -b / gcd
int first_term_denominator; // 2a / gcd
double first_term; // double (-b / 2a)
int second_term_gcd; // gcd(√|Δ|, 2a)
int second_term_numerator; // √|Δ| / gcd
int second_term_denominator; // 2a / gcd
double second_term; // double (√|Δ| / 2a)
double solution1; // first_term + second_term
double solution2; // first_term - second_term (not if DELTA_ZERO)
} s_solution_degree_2;
*/
void solve(const s_polynom *polynom, s_solution *solution)
static void solve_degree_2(s_solution_degree_2 *solution, double a, double b, double c)
{
double delta;
double a;
double b;
double c;
a = polynom[2].coefficient;
b = polynom[1].coefficient;
c = polynom[0].coefficient;
delta = b * b - 4 * a * c;
solution->delta_sign = ft_sign_f(delta);
solution->delta_sign = ft_fsign(delta);
solution->delta_absolute = ft_fabs(delta);
solution->first_term_gcd = find_gcd(b, 2 * a);
solution->first_term_numerator = -b / solution->first_term_gcd;
@@ -114,3 +125,22 @@ void solve(const s_polynom *polynom, s_solution *solution)
// solution->solution2 = 0.0;
// }
}
void solve(const s_polynom *polynom, s_solution *solution)
{
double a;
double b;
double c;
if (solution->degree == 1)
{
}
else if (solution->degree == 2)
{
a = polynom[0].coefficient;
b = polynom[1].coefficient;
c = polynom[2].coefficient;
solve_degree_2(&solution->solution_degree_2, a, b, c);
}
}