From 9ced220c0015f5027669e3a670152c9f0891f4e4 Mon Sep 17 00:00:00 2001 From: hugogogo Date: Wed, 29 Apr 2026 00:58:33 +0200 Subject: [PATCH] add atof --- libft | 2 +- src/computorv1.c | 3 ++- src/lexer.c | 8 +++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libft b/libft index 2be81d5..f86c2cf 160000 --- a/libft +++ b/libft @@ -1 +1 @@ -Subproject commit 2be81d563077fff32c96a82a5748b9de1ff89069 +Subproject commit f86c2cf5cb805cb2bf863b27d42169c5b1f0ccd2 diff --git a/src/computorv1.c b/src/computorv1.c index 1e64621..534d6e2 100644 --- a/src/computorv1.c +++ b/src/computorv1.c @@ -1,6 +1,7 @@ #include "computorv1.h" #include "lexer.h" #include "errors.h" +#include // tmp for float debug int main(int ac, char **av) { @@ -55,7 +56,7 @@ int main(int ac, char **av) if (tokens[i].type == TOKEN_NUMBER) { - ft_printf("%d\n", i, tokens[i].num_value); + printf("%f\n", tokens[i].num_value); } else { diff --git a/src/lexer.c b/src/lexer.c index f15a80b..1517763 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -23,7 +23,7 @@ static bool token_is_variable(const char *input, int input_pos, int *token_size) } // number can be double "123.456" -static bool token_is_number(const char *input, int input_pos, int *token_size) +static bool token_is_number(const char *input, int input_pos, int *token_size, int *float_precision) { int number_size; int max_number_size; @@ -124,9 +124,11 @@ int lexerize(const char *input, token tokens[MAX_TOKENS]) int token_count; int input_pos; int token_size; + int float_precision; token_count = 0; input_pos = 0; + float_precision = 0; while (input[input_pos]) { token_size = 0; @@ -142,10 +144,10 @@ int lexerize(const char *input, token tokens[MAX_TOKENS]) tokens[token_count].type = TOKEN_VARIABLE; tokens[token_count].var_value = 'x'; } - else if (token_is_number(input, input_pos, &token_size)) + else if (token_is_number(input, input_pos, &token_size, &float_precision)) { tokens[token_count].type = TOKEN_NUMBER; - tokens[token_count].num_value = ft_atoi(&input[input_pos]); + tokens[token_count].num_value = ft_atof(&input[input_pos]); } else if (token_is_power(input, input_pos, &token_size)) {