fix modf error

This commit is contained in:
hugogogo
2026-05-10 01:51:35 +02:00
parent ca99f43fe4
commit 5077db3bc6
5 changed files with 42 additions and 20 deletions

View File

@@ -89,11 +89,15 @@ finding the square root of x
## dichotomy method ## dichotomy method
the dichotomie method, or binary search, consist on dividing the range of research by 2 each time, and choosing the right one for the next iteration.
Ex :
``` ```
solution solution
|------------------------------ 1. define range bound_1 : 0 |------------------------------ 1. define range bound_1 : 0
|-----------------------------| 2. choose range bound_2 : x |-----------------------------| 2. define range bound_2 : x
|--------------+--------------| 3. take mid : (bound_1 + bound_2) / 2 |--------------+--------------| 3. take mid : (bound_1 + bound_2) / 2
|--------------|-------ø------| 4. choose range bound : bound_1 or bound_2 |--------------|-------ø------| 4. choose range bound : bound_1 or bound_2
@@ -123,7 +127,9 @@ finding the square root of x
## NewtonRaphson method ## NewtonRaphson method
it's like a self-correcting binary search, we get rid of the step "choose range" : it's like a self-correcting binary search, we get rid of the step "choose range", we use the formulae `x/v` to find the next range, with `x` being the number we are trying to get the sqaure root from, and `v` the value found at the previous step.
Ex :
``` ```
solution solution

View File

@@ -122,6 +122,8 @@ typedef enum
typedef struct typedef struct
{ {
double a; // a in "ax + b"
double b; // b in "ax + b"
int solution_gcd; // gcd(b, a) int solution_gcd; // gcd(b, a)
int solution_numerator; // -b / gcd int solution_numerator; // -b / gcd
int solution_denominator; // a / gcd int solution_denominator; // a / gcd
@@ -130,6 +132,9 @@ typedef struct
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 e_delta_sign delta_sign; // DELTA_PLUS or DELTA_MINUS or DELTA_ZERO
double delta_absolute; // |Δ| == |b² - 4ac| double delta_absolute; // |Δ| == |b² - 4ac|
double delta_sqrt; // √|Δ| double delta_sqrt; // √|Δ|

2
libft

Submodule libft updated: ae9787ba6d...60c72d7560

View File

@@ -103,6 +103,10 @@ static void solve_degree_2(s_solution_degree_2 *solution, double a, double b, do
{ {
double delta; double delta;
solution->a = a;
solution->b = b;
solution->c = c;
delta = b * b - 4 * a * c; delta = b * b - 4 * a * c;
solution->delta_sign = ft_fsign(delta); solution->delta_sign = ft_fsign(delta);
solution->delta_absolute = ft_fabs(delta); solution->delta_absolute = ft_fabs(delta);
@@ -115,7 +119,7 @@ static void solve_degree_2(s_solution_degree_2 *solution, double a, double b, do
solution->first_term = -b / (2 * a); solution->first_term = -b / (2 * a);
// second term // second term
// solution->second_term_gcd = find_gcd(b, 2 * a); solution->second_term_gcd = find_gcd(solution->delta_sqrt, 2 * a);
// solution->second_term_numerator = ; // solution->second_term_numerator = ;
// solution->second_term_denominator = ; // solution->second_term_denominator = ;
// solution->second_term = ; // solution->second_term = ;

View File

@@ -79,19 +79,26 @@ static void print_context_solution()
dprintf(STDERR_FILENO, "degree 2 : delta > 0 ( -b / 2a +- √Δ / 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 )\n");
dprintf(STDERR_FILENO, " delta < 0 ( -b / 2a +- i√|Δ| / 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, "a : %15g\n", solution_2.a);
dprintf(STDERR_FILENO, "delta_sqrt : %25g (√|Δ| )\n", solution_2.delta_sqrt); dprintf(STDERR_FILENO, "b : %15g\n", solution_2.b);
dprintf(STDERR_FILENO, "first_term_gcd : %25i\n", solution_2.first_term_gcd); dprintf(STDERR_FILENO, "c : %15g\n", solution_2.c);
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, "delta_sign : %15s\n", delta_sign_to_str(solution_2.delta_sign));
dprintf(STDERR_FILENO, "first_term : %25g (-b / 2a )\n", solution_2.first_term); dprintf(STDERR_FILENO, "delta_absolute : %15g ( |Δ| == |b² - 4ac| )\n", solution_2.delta_absolute);
// dprintf(STDERR_FILENO, "second_term_gcd : %25g\n", solution_2.second_term_gcd); dprintf(STDERR_FILENO, "delta_sqrt : %15g ( √|Δ| )\n", solution_2.delta_sqrt);
// 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); dprintf(STDERR_FILENO, "first_term_gcd : %15i\n", solution_2.first_term_gcd);
// dprintf(STDERR_FILENO, "second_term : %25g\n", solution_2.second_term); dprintf(STDERR_FILENO, "first_term_numerator : %15i ( -b / gcd )\n", solution_2.first_term_numerator);
// dprintf(STDERR_FILENO, "solution1 : %25g\n", solution_2.solution1); dprintf(STDERR_FILENO, "first_term_denominator : %15i ( 2a / gcd )\n", solution_2.first_term_denominator);
// dprintf(STDERR_FILENO, "solution2 : %25g\n", solution_2.solution2); dprintf(STDERR_FILENO, "first_term : %15g ( -b / 2a )\n", solution_2.first_term);
dprintf(STDERR_FILENO, "second_term_gcd : %15i\n", solution_2.second_term_gcd);
// dprintf(STDERR_FILENO, "second_term_numerator : %15g\n", solution_2.second_term_numerator);
// dprintf(STDERR_FILENO, "second_term_denominator: %15g\n", solution_2.second_term_denominator);
// dprintf(STDERR_FILENO, "second_term : %15g\n", solution_2.second_term);
// dprintf(STDERR_FILENO, "solution1 : %15g\n", solution_2.solution1);
// dprintf(STDERR_FILENO, "solution2 : %15g\n", solution_2.solution2);
} }
ft_putchar_fd('\n', STDERR_FILENO); ft_putchar_fd('\n', STDERR_FILENO);