add positiv_zero in output
This commit is contained in:
@@ -206,6 +206,7 @@ void print_solution(s_solution *solution);
|
||||
bool is_nearly_equal(double num, int compare);
|
||||
bool is_nearly_equal_zero(double num);
|
||||
const s_polynom *get_term_of_power(const s_polynom *polynom, int power);
|
||||
double positiv_zero(double num);
|
||||
bool has_decimal_part(double num);
|
||||
bool any_has_decimal_part(double *num, size_t len);
|
||||
int gcd_int(int a, int b);
|
||||
|
||||
@@ -129,14 +129,14 @@ static void print_solution_pure_radicand_negativ(s_solution_degree_2_pure soluti
|
||||
static void print_solution_delta_zero(s_solution_degree_2 solution)
|
||||
{
|
||||
ft_printf("Discriminant is equal to zero, the solution is:\n");
|
||||
printf("%g\n", solution.left_term);
|
||||
printf("%g\n", positiv_zero(solution.left_term));
|
||||
}
|
||||
|
||||
static void print_solution_delta_positiv(s_solution_degree_2 solution)
|
||||
{
|
||||
ft_printf("Discriminant is strictly positive, the two solutions are:\n");
|
||||
printf("%g\n", solution.left_term + solution.right_term);
|
||||
printf("%g\n", solution.left_term - solution.right_term);
|
||||
printf("%g\n", positiv_zero(solution.left_term + solution.right_term));
|
||||
printf("%g\n", positiv_zero(solution.left_term - solution.right_term));
|
||||
}
|
||||
|
||||
static void print_solution_delta_negativ(s_solution_degree_2 solution)
|
||||
@@ -154,7 +154,7 @@ static void print_solution_delta_negativ(s_solution_degree_2 solution)
|
||||
|
||||
if (solution.all_int)
|
||||
{
|
||||
denominator = solution.a * 2;
|
||||
denominator = positiv_zero(solution.a * 2);
|
||||
denominator_abs = ft_fabs(denominator);
|
||||
denominator_sign = ft_fsign(denominator);
|
||||
// solution 1
|
||||
@@ -167,7 +167,7 @@ static void print_solution_delta_negativ(s_solution_degree_2 solution)
|
||||
printf("- ");
|
||||
else if (has_first_term)
|
||||
printf("+ "); // dont print '+' if it's first term
|
||||
printf("%gi/%g\n", solution.delta_sqrt, denominator_abs);
|
||||
printf("%gi/%g\n", positiv_zero(solution.delta_sqrt), denominator_abs);
|
||||
|
||||
// solution 2
|
||||
if (!is_nearly_equal_zero(solution.b))
|
||||
@@ -179,11 +179,11 @@ static void print_solution_delta_negativ(s_solution_degree_2 solution)
|
||||
printf("- ");
|
||||
else if (has_first_term)
|
||||
printf("+ "); // dont print '+' if it's first term
|
||||
printf("%gi/%g\n", solution.delta_sqrt, denominator_abs);
|
||||
printf("%gi/%g\n", positiv_zero(solution.delta_sqrt), denominator_abs);
|
||||
}
|
||||
else
|
||||
{
|
||||
right_term_abs = ft_fabs(solution.right_term);
|
||||
right_term_abs = positiv_zero(ft_fabs(solution.right_term));
|
||||
right_term_sign = ft_fsign(solution.right_term);
|
||||
|
||||
// solution 1
|
||||
|
||||
@@ -2,13 +2,6 @@
|
||||
|
||||
#include "computorv1.h"
|
||||
|
||||
static double positiv_zero(double num)
|
||||
{
|
||||
if (num == 0)
|
||||
return 0;
|
||||
return num;
|
||||
}
|
||||
|
||||
static void solve_degree_1(s_solution_degree_1 *solution, double a, double b)
|
||||
{
|
||||
solution->a = a;
|
||||
|
||||
@@ -31,6 +31,13 @@ const s_polynom *get_term_of_power(const s_polynom *polynom, int power)
|
||||
return &polynom[i];
|
||||
}
|
||||
|
||||
double positiv_zero(double num)
|
||||
{
|
||||
if (is_nearly_equal_zero(num))
|
||||
return 0.0;
|
||||
return num;
|
||||
}
|
||||
|
||||
bool has_decimal_part(double num)
|
||||
{
|
||||
return (!is_nearly_equal(num, (int)num));
|
||||
|
||||
14
tester.sh
14
tester.sh
@@ -170,17 +170,17 @@ run_test \
|
||||
Reduced form: 0 * x^0 + 2 * x^1 + 3 * x^2 = 0
|
||||
Polynomial degree: 2
|
||||
Discriminant is strictly positive, the two solutions are:
|
||||
2.66667
|
||||
-3.33333"
|
||||
0
|
||||
-0.666667"
|
||||
|
||||
run_test \
|
||||
"6. degree 2" \
|
||||
"3.4 * x^2 + 1 * x^1 - 2.0 * x^0 = 5.123 * x^1" "\
|
||||
Reduced form: 2 * x^0 - 4.123 * x^1 + 3.4 * x^2 = 0
|
||||
Reduced form: -2 * x^0 - 4.123 * x^1 + 3.4 * x^2 = 0
|
||||
Polynomial degree: 2
|
||||
Discriminant is strictly negative, the two complex solutions are:
|
||||
4.123/6.8 + 3.19388i/6.8
|
||||
4.123/6.8 - 3.19388i/6.8"
|
||||
Discriminant is strictly positive, the two solutions are:
|
||||
1.58401
|
||||
-0.371359"
|
||||
|
||||
run_test \
|
||||
"7. float exponent" \
|
||||
@@ -191,7 +191,7 @@ error
|
||||
run_test \
|
||||
"8. degree 4" \
|
||||
"3x^2 + 2x -7x^4 = x^4" "\
|
||||
Reduced form: 0 * x^0 + 2 * x^1 + 3 * x^2 + 6 * x^4 = 0
|
||||
Reduced form: 0 * x^0 + 2 * x^1 + 3 * x^2 + 0 * x^3 - 8 * x^4 = 0
|
||||
Polynomial degree: 4
|
||||
The polynomial degree is strictly greater than 2, I can't solve."
|
||||
|
||||
|
||||
Reference in New Issue
Block a user