update readme with sqrt explication
This commit is contained in:
16
src/solver.c
16
src/solver.c
@@ -71,8 +71,6 @@ static int find_gcd(double numerator, double denominator)
|
||||
/*
|
||||
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
|
||||
@@ -82,19 +80,20 @@ typedef struct
|
||||
/*
|
||||
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|
|
||||
double delta_sqrt; // √|Δ|
|
||||
|
||||
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;
|
||||
@@ -107,11 +106,16 @@ static void solve_degree_2(s_solution_degree_2 *solution, double a, double b, do
|
||||
delta = b * b - 4 * a * c;
|
||||
solution->delta_sign = ft_fsign(delta);
|
||||
solution->delta_absolute = ft_fabs(delta);
|
||||
solution->delta_sqrt = ft_sqrt(solution->delta_absolute);
|
||||
|
||||
// first term
|
||||
solution->first_term_gcd = find_gcd(b, 2 * a);
|
||||
solution->first_term_numerator = -b / solution->first_term_gcd;
|
||||
solution->first_term_denominator = 2 * a / solution->first_term_gcd;
|
||||
solution->first_term = -b / (2 * a);
|
||||
// solution->second_term_gcd = ;
|
||||
|
||||
// second term
|
||||
// solution->second_term_gcd = find_gcd(b, 2 * a);
|
||||
// solution->second_term_numerator = ;
|
||||
// solution->second_term_denominator = ;
|
||||
// solution->second_term = ;
|
||||
|
||||
Reference in New Issue
Block a user