fix complex sign operation
This commit is contained in:
@@ -141,36 +141,76 @@ static void print_solution_delta_positiv(s_solution_degree_2 solution)
|
||||
|
||||
static void print_solution_delta_negativ(s_solution_degree_2 solution)
|
||||
{
|
||||
double denominator;
|
||||
double denominator_abs;
|
||||
int denominator_sign;
|
||||
double right_term_abs;
|
||||
int right_term_sign;
|
||||
bool has_first_term;
|
||||
|
||||
ft_printf("Discriminant is strictly negative, the two complex solutions are:\n");
|
||||
|
||||
has_first_term = false;
|
||||
|
||||
if (solution.all_int)
|
||||
{
|
||||
denominator = solution.a * 2;
|
||||
denominator_abs = ft_fabs(denominator);
|
||||
denominator_sign = ft_fsign(denominator);
|
||||
// solution 1
|
||||
if (!is_nearly_equal_zero(solution.b))
|
||||
printf("%g/%g + ", solution.b * -1, solution.a * 2);
|
||||
printf("%gi/%g\n", solution.delta_sqrt, solution.a * 2);
|
||||
{
|
||||
has_first_term = true;
|
||||
printf("%g/%g ", solution.b * -1 * denominator_sign, denominator_abs);
|
||||
}
|
||||
if (denominator_sign == -1)
|
||||
printf("- ");
|
||||
else if (has_first_term)
|
||||
printf("+ "); // dont print '+' if it's first term
|
||||
printf("%gi/%g\n", solution.delta_sqrt, denominator_abs);
|
||||
|
||||
// solution 2
|
||||
if (!is_nearly_equal_zero(solution.b))
|
||||
printf("%g/%g - ", solution.b * -1, solution.a * 2);
|
||||
else
|
||||
printf("-");
|
||||
printf("%gi/%g\n", solution.delta_sqrt, solution.a * 2);
|
||||
{
|
||||
has_first_term = true;
|
||||
printf("%g/%g ", solution.b * -1 * denominator_sign, denominator_abs);
|
||||
}
|
||||
if (denominator_sign == 1)
|
||||
printf("- ");
|
||||
else if (has_first_term)
|
||||
printf("+ "); // dont print '+' if it's first term
|
||||
printf("%gi/%g\n", solution.delta_sqrt, denominator_abs);
|
||||
}
|
||||
else
|
||||
{
|
||||
right_term_abs = ft_fabs(solution.right_term);
|
||||
right_term_sign = ft_fsign(solution.right_term);
|
||||
|
||||
// solution 1
|
||||
if (!is_nearly_equal_zero(solution.left_term))
|
||||
printf("%g + ", solution.left_term);
|
||||
if (!is_nearly_equal_zero(solution.right_term))
|
||||
printf("i * %g\n", solution.right_term);
|
||||
{
|
||||
has_first_term = true;
|
||||
printf("%g ", solution.left_term);
|
||||
}
|
||||
if (right_term_sign == -1)
|
||||
printf("- ");
|
||||
else if (has_first_term)
|
||||
printf("+ "); // dont print '+' if it's first term
|
||||
if (!is_nearly_equal_zero(right_term_abs))
|
||||
printf("%g*i\n", right_term_abs);
|
||||
|
||||
// solution 2
|
||||
if (!is_nearly_equal_zero(solution.left_term))
|
||||
printf("%g - ", solution.left_term);
|
||||
else
|
||||
printf("-");
|
||||
printf("i * %g\n", solution.right_term);
|
||||
{
|
||||
has_first_term = true;
|
||||
printf("%g ", solution.left_term);
|
||||
}
|
||||
if (right_term_sign == 1)
|
||||
printf("- ");
|
||||
else if (has_first_term)
|
||||
printf("+ "); // dont print '+' if it's first term
|
||||
if (!is_nearly_equal_zero(right_term_abs))
|
||||
printf("%g*i\n", right_term_abs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user