update readme with sqrt explication

This commit is contained in:
hugogogo
2026-05-09 14:45:19 +02:00
parent 43b4def6ce
commit ca99f43fe4
5 changed files with 182 additions and 16 deletions

View File

@@ -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 = ;

View File

@@ -76,15 +76,16 @@ static void print_context_solution()
if (solution_g_err->degree == 2)
{
solution_2 = solution_g_err->solution_degree_2;
dprintf(STDERR_FILENO, "degree 2 : delta > 0 ( -b/2a +- √Δ/2a )\n");
dprintf(STDERR_FILENO, " delta == 0 ( -b/2a )\n");
dprintf(STDERR_FILENO, "degree 2 : delta > 0 ( -b/2a +- √Δ/2a )\n");
dprintf(STDERR_FILENO, " delta == 0 ( -b/2a )\n");
dprintf(STDERR_FILENO, " delta < 0 ( -b/2a +- i√|Δ|/2a )\n");
dprintf(STDERR_FILENO, "delta_sign : %25s\n", delta_sign_to_str(solution_2.delta_sign));
dprintf(STDERR_FILENO, "delta_absolute : %25g (|b² - 4ac|)\n", solution_2.delta_absolute);
dprintf(STDERR_FILENO, "delta_absolute : %25g ( |Δ| == |b² - 4ac| )\n", solution_2.delta_absolute);
dprintf(STDERR_FILENO, "delta_sqrt : %25g (√|Δ| )\n", solution_2.delta_sqrt);
dprintf(STDERR_FILENO, "first_term_gcd : %25i\n", solution_2.first_term_gcd);
dprintf(STDERR_FILENO, "first_term_numerator : %25i (-b / gcd)\n", solution_2.first_term_numerator);
dprintf(STDERR_FILENO, "first_term_denominator : %25i (2a / gcd)\n", solution_2.first_term_denominator);
dprintf(STDERR_FILENO, "first_term : %25g (-b / 2a)\n", solution_2.first_term);
dprintf(STDERR_FILENO, "first_term_numerator : %25i (-b / gcd )\n", solution_2.first_term_numerator);
dprintf(STDERR_FILENO, "first_term_denominator : %25i (2a / gcd )\n", solution_2.first_term_denominator);
dprintf(STDERR_FILENO, "first_term : %25g (-b / 2a )\n", solution_2.first_term);
// dprintf(STDERR_FILENO, "second_term_gcd : %25g\n", solution_2.second_term_gcd);
// dprintf(STDERR_FILENO, "second_term_numerator : %25g\n", solution_2.second_term_numerator);
// dprintf(STDERR_FILENO, "second_term_denominator: %25g\n", solution_2.second_term_denominator);