fix null coefficient skipped
This commit is contained in:
33
src/solver.c
33
src/solver.c
@@ -2,6 +2,29 @@
|
||||
|
||||
#include "computorv1.h"
|
||||
|
||||
static double get_coefficient_of_power(int power, const s_polynom *polynom)
|
||||
{
|
||||
int i;
|
||||
double coefficient;
|
||||
|
||||
// if no term found with exponent, default coefficient is 0
|
||||
coefficient = 0;
|
||||
|
||||
i = 0;
|
||||
while (polynom[i].sign != TERM_SIGN_END)
|
||||
{
|
||||
if (polynom[i].exponent == power)
|
||||
{
|
||||
coefficient = polynom[i].coefficient;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
print_debug("- coefficient of power '%i' : %g (polynom[%i])\n", power, coefficient, i);
|
||||
return coefficient;
|
||||
}
|
||||
|
||||
static double positiv_zero(double num)
|
||||
{
|
||||
if (num == 0)
|
||||
@@ -48,16 +71,16 @@ void solve(const s_polynom *polynom, s_solution *solution)
|
||||
|
||||
if (solution->degree == 1)
|
||||
{
|
||||
a = polynom[0].coefficient;
|
||||
b = polynom[1].coefficient;
|
||||
a = get_coefficient_of_power(1, polynom);
|
||||
b = get_coefficient_of_power(0, polynom);
|
||||
|
||||
solve_degree_1(&solution->solution_degree_1, a, b);
|
||||
}
|
||||
else if (solution->degree == 2)
|
||||
{
|
||||
a = polynom[0].coefficient;
|
||||
b = polynom[1].coefficient;
|
||||
c = polynom[2].coefficient;
|
||||
a = get_coefficient_of_power(2, polynom);
|
||||
b = get_coefficient_of_power(1, polynom);
|
||||
c = get_coefficient_of_power(0, polynom);
|
||||
|
||||
solve_degree_2(&solution->solution_degree_2, a, b, c);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user