add logic for pure quadratics
This commit is contained in:
@@ -124,6 +124,13 @@ typedef enum
|
||||
DELTA_MINUS = -1,
|
||||
} e_delta_sign;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RADICAND_ZERO = 0,
|
||||
RADICAND_PLUS = 1,
|
||||
RADICAND_MINUS = -1,
|
||||
} e_radicand_sign;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double a; // a in "ax + b"
|
||||
@@ -136,8 +143,8 @@ 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; // Δ == b² - 4ac
|
||||
e_delta_sign delta_sign; // DELTA_PLUS or DELTA_MINUS or DELTA_ZERO
|
||||
double delta_absolute; // |Δ|
|
||||
double delta_sqrt; // √|Δ|
|
||||
double left_term; // double (-b / 2a)
|
||||
@@ -149,13 +156,29 @@ typedef struct
|
||||
int right_term_denominator; // 2a / gcd
|
||||
} s_solution_degree_2;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double a; // a in "ax² + c"
|
||||
double c; // c in "ax² + c"
|
||||
double radicand; // x² = -c/a
|
||||
e_radicand_sign radicand_sign; // RADICAND_PLUS or RADICAND_MINUS or RADICAND_ZERO
|
||||
double radicand_absolute; // |radicand|
|
||||
double radicand_sqrt; // √|radicand|
|
||||
double numerator_sqrt; // √a
|
||||
bool numerator_sqrt_is_int; // false if √a is a double
|
||||
double denominator_sqrt; // √c
|
||||
bool denominator_sqrt_is_int; // false if √c is a double
|
||||
} s_solution_degree_2_pure;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int degree;
|
||||
bool is_quadratic_pure;
|
||||
union
|
||||
{
|
||||
s_solution_degree_1 solution_degree_1;
|
||||
s_solution_degree_2 solution_degree_2;
|
||||
s_solution_degree_2_pure solution_degree_2_pure;
|
||||
};
|
||||
} s_solution;
|
||||
|
||||
@@ -166,6 +189,10 @@ void solve(const s_polynom *polynom, s_solution *solution);
|
||||
*/
|
||||
|
||||
bool is_nearly_equal_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);
|
||||
int reduce_fraction(double *numerator, double *denominator);
|
||||
|
||||
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* UTILS/ERRORS.C
|
||||
@@ -183,6 +210,7 @@ const char *token_tag_to_str(e_token_tag tag);
|
||||
const char *term_position_to_str(e_term_position pos);
|
||||
const char *term_sign_to_str(e_term_sign sign);
|
||||
const char *delta_sign_to_str(e_delta_sign sign);
|
||||
const char *radicand_sign_to_str(e_radicand_sign enum_value);
|
||||
|
||||
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* UTILS/PRINT_DEBUG.C
|
||||
|
||||
Reference in New Issue
Block a user