init solver

This commit is contained in:
hugogogo
2026-05-06 22:26:58 +02:00
parent 16c57c9bea
commit 4c13d21e1f
11 changed files with 159 additions and 75 deletions

View File

@@ -66,7 +66,7 @@ typedef struct
};
} s_token;
int lexerize(const char *input, s_token *tokens);
void lexerize(const char *input, s_token *tokens);
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* PARSER.C
@@ -94,7 +94,7 @@ typedef struct
int exponent;
} s_term;
int parse(s_token *tokens, s_term *terms, int terms_count_max);
void parse(s_token *tokens, s_term *terms, int terms_count_max);
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* REDUCE.C
@@ -102,6 +102,35 @@ int parse(s_token *tokens, s_term *terms, int terms_count_max);
void reduce(s_term *terms, double *polynom);
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* SOLVE.C
*/
typedef enum
{
DELTA_PLUS, // +
DELTA_MINUS, // -
DELTA_ZERO, // 0
} e_delta_sign;
typedef struct
{
e_delta_sign delta_sign; // DELTA_PLUS or DELTA_MINUS or DELTA_ZERO
double delta_absolute; // |Δ| == |b² - 4ac|
int first_term_pgcd; // pgcd(b, 2a)
int first_term_numerator; // -b / pgcd
int first_term_denominator; // 2a / pgcd
double first_term; // double (-b / 2a)
int second_term_pgcd; // pgcd(√|Δ|, 2a)
int second_term_numerator; // √|Δ| / pgcd
int second_term_denominator; // 2a / pgcd
double second_term; // double (√|Δ| / 2a)
double solution1; // first_term + second_term
double solution2; // first_term - second_term
} s_solution;
void solve(const double *polynom, s_solution *solution);
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* UTILS/ERRORS.C
*/
@@ -117,6 +146,7 @@ const char *token_type_to_str(e_token_type type);
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);
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* UTILS/PRINTER.C
@@ -135,5 +165,6 @@ extern double *polynom_g_err;
extern int polynom_len_g_err;
extern bool flag_debug_mode;
extern bool flag_loop_mode;
extern s_solution *solution_g_err;
#endif