add atof
This commit is contained in:
2
libft
2
libft
Submodule libft updated: 2be81d5630...f86c2cf5cb
@@ -1,6 +1,7 @@
|
||||
#include "computorv1.h"
|
||||
#include "lexer.h"
|
||||
#include "errors.h"
|
||||
#include <stdio.h> // 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
|
||||
{
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user