reduced form calculated

This commit is contained in:
hugogogo
2026-05-03 23:57:47 +02:00
parent 3420923557
commit edc678cee4
6 changed files with 52 additions and 9 deletions

View File

@@ -66,7 +66,7 @@ static double get_double_value(s_token token)
return token.value_int;
}
static double get_coefficient(s_token *tokens, int i, int *token_count)
static double get_coefficient_absolute(s_token *tokens, int i, int *token_count)
{
double coefficient;
@@ -227,6 +227,7 @@ int parse(s_token *tokens, s_term *terms, int terms_count_max)
int i;
int terms_count;
int token_count;
int sign;
e_term_position term_position;
check_variables(tokens);
@@ -251,14 +252,19 @@ int parse(s_token *tokens, s_term *terms, int terms_count_max)
terms[terms_count].position = term_position;
// sign
sign = 1;
e_term_sign ret_sign = get_sign(tokens, i, &token_count);
terms[terms_count].sign = ret_sign;
if (ret_sign == TERM_MINUS)
{
sign = -1;
}
i += token_count;
// ft_printf("term[%i] get_sign: (%i)[%s], token_count: [%d]\n", terms_count, ret_sign, term_sign_to_str(ret_sign), token_count); // debug
// coefficient
double ret_coefficient = get_coefficient(tokens, i, &token_count);
terms[terms_count].coefficient = ret_coefficient;
double ret_coefficient = get_coefficient_absolute(tokens, i, &token_count);
terms[terms_count].coefficient = ret_coefficient * sign;
i += token_count;
// printf("term[%i] get_coefficient: [%g], token_count: [%d]\n", terms_count, ret_coefficient, token_count); // debug