fix superscript 1
This commit is contained in:
4
Makefile
4
Makefile
@@ -118,8 +118,10 @@ run: $(NAME)
|
|||||||
-./$(NAME) -d "3x^2 + 2x -7x^4 = x^4"
|
-./$(NAME) -d "3x^2 + 2x -7x^4 = x^4"
|
||||||
@echo $(B_PURPLE)"\n---------------------------------------------\n9. run with utf8 \n"$(RESET)
|
@echo $(B_PURPLE)"\n---------------------------------------------\n9. run with utf8 \n"$(RESET)
|
||||||
-./$(NAME) -d "3x² + 2x -7x¹ = x"
|
-./$(NAME) -d "3x² + 2x -7x¹ = x"
|
||||||
@echo $(B_PURPLE)"\n---------------------------------------------\n9. run normal \n"$(RESET)
|
@echo $(B_PURPLE)"\n---------------------------------------------\n10. run normal \n"$(RESET)
|
||||||
-./$(NAME) -d "3x² + 2x -7 = x"
|
-./$(NAME) -d "3x² + 2x -7 = x"
|
||||||
|
@echo $(B_PURPLE)"\n---------------------------------------------\n11. run \n"$(RESET)
|
||||||
|
-./$(NAME) "3x² + 2x -7 = x"
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM_OBJS)
|
$(RM_OBJS)
|
||||||
|
|||||||
14
README.md
14
README.md
@@ -41,9 +41,15 @@ this project uses submodules (maybe recursively), so either :
|
|||||||
- 3
|
- 3
|
||||||
- ...
|
- ...
|
||||||
4. print reduced form
|
4. print reduced form
|
||||||
5. find degree
|
-> print reduced form
|
||||||
6. print degree
|
-> if degree 1 :
|
||||||
7. solve
|
- if c = 0 -> print "any real is a solution"
|
||||||
|
- if c != 0 -> print "no solution"
|
||||||
|
-> if degree 2 :
|
||||||
|
- print degree
|
||||||
|
-> if degree 3 :
|
||||||
|
- print degree
|
||||||
|
5. solve
|
||||||
-> discriminant : Δ = b² - 4ac
|
-> discriminant : Δ = b² - 4ac
|
||||||
-> Δ > 0 -> 2 solutions : x = ( -b / 2a ) +- ( √|Δ| / 2a )
|
-> Δ > 0 -> 2 solutions : x = ( -b / 2a ) +- ( √|Δ| / 2a )
|
||||||
-> Δ == 0 -> : x = ( -b / 2a )
|
-> Δ == 0 -> : x = ( -b / 2a )
|
||||||
@@ -61,4 +67,4 @@ this project uses submodules (maybe recursively), so either :
|
|||||||
- second_term; // double (√|Δ| / 2a)
|
- second_term; // double (√|Δ| / 2a)
|
||||||
- double solution1; // first_term + second_term
|
- double solution1; // first_term + second_term
|
||||||
- double solution2; // first_term - second_term
|
- double solution2; // first_term - second_term
|
||||||
8. print solution
|
6. print solution
|
||||||
|
|||||||
@@ -155,7 +155,8 @@ const char *delta_sign_to_str(e_delta_sign sign);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
void print_debug(const char *description, ...);
|
void print_debug(const char *description, ...);
|
||||||
void print_before_solution(double *polynom, int max_exponent);
|
void print_reduced_form(double *polynom, int max_exponent);
|
||||||
|
void print_degree(double *polynom, int max_exponent);
|
||||||
|
|
||||||
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
* GLOBALS
|
* GLOBALS
|
||||||
@@ -166,8 +167,9 @@ extern s_token *tokens_g_err;
|
|||||||
extern s_term *terms_g_err;
|
extern s_term *terms_g_err;
|
||||||
extern double *polynom_g_err;
|
extern double *polynom_g_err;
|
||||||
extern int polynom_len_g_err;
|
extern int polynom_len_g_err;
|
||||||
|
extern s_solution *solution_g_err;
|
||||||
extern bool flag_debug_mode;
|
extern bool flag_debug_mode;
|
||||||
extern bool flag_loop_mode;
|
extern bool flag_loop_mode;
|
||||||
extern s_solution *solution_g_err;
|
extern bool flag_beautify_mode;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
2
libft
2
libft
Submodule libft updated: 413e149003...aa35d294f2
@@ -109,8 +109,8 @@ void launch_computorv1(char *input)
|
|||||||
remove_spaces(input);
|
remove_spaces(input);
|
||||||
|
|
||||||
// lexerize
|
// lexerize
|
||||||
arg_len = ft_strlen(input) + 1; // +1 for last END token
|
arg_len = ft_strlen(input) + 1; // +1 for last END token
|
||||||
print_debug("\n-> tokens[%i]\n", arg_len); // debug
|
print_debug("\n-> tokens[%i]\n", arg_len);
|
||||||
s_token tokens[arg_len];
|
s_token tokens[arg_len];
|
||||||
tokens_g_err = tokens;
|
tokens_g_err = tokens;
|
||||||
tokens_fill_null(tokens, arg_len);
|
tokens_fill_null(tokens, arg_len);
|
||||||
@@ -118,7 +118,7 @@ void launch_computorv1(char *input)
|
|||||||
|
|
||||||
// parse
|
// parse
|
||||||
terms_count_prediction = count_any_of(input, "-+=") + 2; // +1 for first term that can have no leading '+', +1 for last term == NULL
|
terms_count_prediction = count_any_of(input, "-+=") + 2; // +1 for first term that can have no leading '+', +1 for last term == NULL
|
||||||
print_debug("-> terms[%i]\n\n", terms_count_prediction); // debug
|
print_debug("-> terms[%i]\n\n", terms_count_prediction);
|
||||||
s_term terms[terms_count_prediction];
|
s_term terms[terms_count_prediction];
|
||||||
terms_g_err = terms;
|
terms_g_err = terms;
|
||||||
terms_fill_null(terms, terms_count_prediction);
|
terms_fill_null(terms, terms_count_prediction);
|
||||||
@@ -126,7 +126,7 @@ void launch_computorv1(char *input)
|
|||||||
|
|
||||||
// reduce
|
// reduce
|
||||||
max_exponent = get_max_exponent(terms);
|
max_exponent = get_max_exponent(terms);
|
||||||
print_debug("-> max_exponent: %i\n\n", max_exponent); // debug
|
print_debug("-> max_exponent: %i\n\n", max_exponent);
|
||||||
double polynom[max_exponent + 1];
|
double polynom[max_exponent + 1];
|
||||||
polynom_g_err = polynom;
|
polynom_g_err = polynom;
|
||||||
polynom_len_g_err = max_exponent;
|
polynom_len_g_err = max_exponent;
|
||||||
@@ -134,7 +134,8 @@ void launch_computorv1(char *input)
|
|||||||
reduce(terms, polynom);
|
reduce(terms, polynom);
|
||||||
|
|
||||||
// print before solution
|
// print before solution
|
||||||
print_before_solution(polynom, max_exponent);
|
print_reduced_form(polynom, max_exponent);
|
||||||
|
print_degree(polynom, max_exponent);
|
||||||
|
|
||||||
// solve
|
// solve
|
||||||
s_solution solution[1];
|
s_solution solution[1];
|
||||||
|
|||||||
@@ -294,13 +294,13 @@ void lexerize(const char *input, s_token *tokens)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stop_errors(&input[input_pos]);
|
stop_errors("input[input_pos] is not any token: %s\n", &input[input_pos]);
|
||||||
}
|
}
|
||||||
|
|
||||||
tokens_count++;
|
tokens_count++;
|
||||||
if (token_size == 0)
|
if (token_size == 0)
|
||||||
{
|
{
|
||||||
stop_errors(&input[input_pos]);
|
stop_errors("token_size is 0 : %s\n", &input[input_pos]);
|
||||||
}
|
}
|
||||||
input_pos += token_size;
|
input_pos += token_size;
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/main.c
23
src/main.c
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
bool flag_debug_mode;
|
bool flag_debug_mode;
|
||||||
bool flag_loop_mode;
|
bool flag_loop_mode;
|
||||||
|
bool flag_beautify_mode;
|
||||||
char *input_g_err;
|
char *input_g_err;
|
||||||
s_token *tokens_g_err;
|
s_token *tokens_g_err;
|
||||||
s_term *terms_g_err;
|
s_term *terms_g_err;
|
||||||
@@ -19,6 +20,19 @@ s_solution *solution_g_err;
|
|||||||
* PROGRAM
|
* PROGRAM
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static void print_usage()
|
||||||
|
{
|
||||||
|
ft_printf("USAGE :\n\n");
|
||||||
|
ft_printf("| ./computorv1 [flags] [polynom]\n");
|
||||||
|
ft_printf("| ./computorv1 [polynom] [flags]\n");
|
||||||
|
ft_printf("| ./computorv1 [flags] -> interactiv mode\n\n");
|
||||||
|
ft_printf("[flags] :\n");
|
||||||
|
ft_printf("-d : print debug\n");
|
||||||
|
ft_printf("-l : interactive loop\n");
|
||||||
|
ft_printf("-b : beautify output\n");
|
||||||
|
ft_putchar('\n');
|
||||||
|
}
|
||||||
|
|
||||||
// trim spaces and quotes and newlines
|
// trim spaces and quotes and newlines
|
||||||
static void clean_copy_input(char *input, char *line)
|
static void clean_copy_input(char *input, char *line)
|
||||||
{
|
{
|
||||||
@@ -122,15 +136,24 @@ int main(int ac, char **av)
|
|||||||
{
|
{
|
||||||
if ((ft_strcmp(av[i], "-d") == 0))
|
if ((ft_strcmp(av[i], "-d") == 0))
|
||||||
{
|
{
|
||||||
|
// flag -d : debug
|
||||||
flag_debug_mode = true;
|
flag_debug_mode = true;
|
||||||
}
|
}
|
||||||
else if ((ft_strcmp(av[i], "-l") == 0))
|
else if ((ft_strcmp(av[i], "-l") == 0))
|
||||||
{
|
{
|
||||||
|
// flag -l : interactiv loop
|
||||||
flag_loop_mode = true;
|
flag_loop_mode = true;
|
||||||
program_mode = MODE_LOOP;
|
program_mode = MODE_LOOP;
|
||||||
}
|
}
|
||||||
|
else if ((ft_strcmp(av[i], "-l") == 0))
|
||||||
|
{
|
||||||
|
// flag -b : beautify output
|
||||||
|
flag_beautify_mode = true;
|
||||||
|
}
|
||||||
else if (ft_strlen(av[i]) == 2 && av[i][0] == '-')
|
else if (ft_strlen(av[i]) == 2 && av[i][0] == '-')
|
||||||
{
|
{
|
||||||
|
// unknown flag
|
||||||
|
print_usage();
|
||||||
stop_errors("unknwon flag '%s'", av[i]);
|
stop_errors("unknwon flag '%s'", av[i]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ void stop_errors(const char *description, ...)
|
|||||||
va_start(args, description);
|
va_start(args, description);
|
||||||
ft_vdprintf(STDERR_FILENO, description, args);
|
ft_vdprintf(STDERR_FILENO, description, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
ft_putchar_fd('\n', STDERR_FILENO);
|
||||||
|
|
||||||
// print the base message
|
// print the base message
|
||||||
if (flag_debug_mode)
|
if (flag_debug_mode)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ void print_debug(const char *description, ...)
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_before_solution(double *polynom, int max_exponent)
|
void print_reduced_form(double *polynom, int max_exponent)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -40,16 +40,33 @@ void print_before_solution(double *polynom, int max_exponent)
|
|||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
ft_putstr("= 0\n");
|
ft_putstr("= 0\n");
|
||||||
|
}
|
||||||
|
|
||||||
// // check errors
|
void print_degree(double *polynom, int max_exponent)
|
||||||
// ft_printf(": ");
|
{
|
||||||
// ft_printf(": ");
|
|
||||||
// ft_printf(": ");
|
|
||||||
|
|
||||||
// degree
|
if (max_exponent == 0)
|
||||||
ft_printf("Polynomial degree: %i\n", max_exponent);
|
|
||||||
if (max_exponent > 2)
|
|
||||||
{
|
{
|
||||||
|
if (polynom[0] == 0)
|
||||||
|
{
|
||||||
|
stop_errors("Any real number is a solution.\n");
|
||||||
|
}
|
||||||
|
else if (polynom[0] != 0)
|
||||||
|
{
|
||||||
|
stop_errors("No solution.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (max_exponent == 1)
|
||||||
|
{
|
||||||
|
ft_printf("Polynomial degree: %i\n", max_exponent);
|
||||||
|
}
|
||||||
|
else if (max_exponent == 2)
|
||||||
|
{
|
||||||
|
ft_printf("Polynomial degree: %i\n", max_exponent);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ft_printf("Polynomial degree: %i\n", max_exponent);
|
||||||
stop_errors("The polynomial degree is strictly greater than 2, I can't solve.\n");
|
stop_errors("The polynomial degree is strictly greater than 2, I can't solve.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user