Adding the start of math
This commit is contained in:
parent
93f734f5e9
commit
3ac78b4c7f
13 changed files with 628 additions and 0 deletions
39
math/sources/utils/ft_init_numbers.c
Normal file
39
math/sources/utils/ft_init_numbers.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_init_numbers.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/28 13:41:03 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/28 15:44:24 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/ft_math.h"
|
||||
|
||||
t_error ft_init_numbers(t_str str, t_number *nb)
|
||||
{
|
||||
t_usize int_size;
|
||||
t_usize float_size;
|
||||
t_str *tmp;
|
||||
|
||||
int_size = 0;
|
||||
float_size = 0;
|
||||
if (nb == NULL)
|
||||
return (ERROR);
|
||||
if (ft_nblen(str, &int_size, &float_size) == ERROR)
|
||||
return (ERROR);
|
||||
else
|
||||
{
|
||||
nb = (t_number *)malloc(sizeof(t_number));
|
||||
nb->number = str;
|
||||
tmp = ft_split(str, '.');
|
||||
nb->int_part = tmp[0];
|
||||
nb->float_part = tmp[1];
|
||||
// free_strs(tmp);
|
||||
nb->int_size = int_size;
|
||||
nb->float_size = float_size;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
}
|
||||
44
math/sources/utils/ft_nblen.c
Normal file
44
math/sources/utils/ft_nblen.c
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_nblen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/27 12:30:54 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/28 13:34:20 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/ft_math.h"
|
||||
|
||||
t_error ft_counter(const t_str str, t_usize *i)
|
||||
{
|
||||
if (str[(*i)] >= '0' && str[(*i)] <= '9')
|
||||
(*i)++;
|
||||
else
|
||||
return (ERROR);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error ft_nblen(const t_str str, t_usize *int_len, t_usize *float_len)
|
||||
{
|
||||
t_usize i;
|
||||
|
||||
(*int_len) = 0;
|
||||
(*float_len) = 0;
|
||||
i = 0;
|
||||
if (str == NULL)
|
||||
return (ERROR);
|
||||
while (str[i] != '.' && str[i] != '\0')
|
||||
ft_counter(str, &i);
|
||||
(*int_len) = i;
|
||||
if (str[i] == '.')
|
||||
{
|
||||
i++;
|
||||
while (str[i] != '\0')
|
||||
ft_counter(str, &i);
|
||||
(*float_len) = i - (*int_len) - 1;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue