Adding the start of math
This commit is contained in:
parent
93f734f5e9
commit
3ac78b4c7f
13 changed files with 628 additions and 0 deletions
21
math/sources/comparison/ft_equal.c
Normal file
21
math/sources/comparison/ft_equal.c
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_equal.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/04 15:43:23 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/28 14:12:46 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/ft_math.h"
|
||||
|
||||
// char ft_equal(double nb1, double nb2)
|
||||
// {
|
||||
// if (nb1 == nb2)
|
||||
// return (1);
|
||||
// else
|
||||
// return (0);
|
||||
// }
|
||||
29
math/sources/comparison/ft_is_greater.c
Normal file
29
math/sources/comparison/ft_is_greater.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_is_greater.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/04 14:29:09 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/28 14:13:23 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/ft_math.h"
|
||||
|
||||
// char ft_is_greater_equal(double nb1, double nb2)
|
||||
// {
|
||||
// if (nb1 >= nb2)
|
||||
// return (1);
|
||||
// else
|
||||
// return (0);
|
||||
// }
|
||||
//
|
||||
// char ft_is_greater(double nb1, double nb2)
|
||||
// {
|
||||
// if (nb1 > nb2)
|
||||
// return (1);
|
||||
// else
|
||||
// return (0);
|
||||
// }
|
||||
30
math/sources/comparison/ft_is_less.c
Normal file
30
math/sources/comparison/ft_is_less.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_is_less.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/04 14:39:13 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/28 14:12:59 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/ft_math.h"
|
||||
|
||||
// char ft_is_less_equal(double nb1, double nb2)
|
||||
// {
|
||||
// if (nb1 <= nb2)
|
||||
// return (1);
|
||||
// else
|
||||
// return (0);
|
||||
// }
|
||||
//
|
||||
// char ft_is_less(double nb1, double nb2)
|
||||
// {
|
||||
// if (nb1 < nb2)
|
||||
// return (1);
|
||||
// else
|
||||
// return (0);
|
||||
// }
|
||||
//
|
||||
93
math/sources/ft_split.c
Normal file
93
math/sources/ft_split.c
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:56:02 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/28 15:39:50 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/ft_math.h"
|
||||
|
||||
static int count_words(const char *str, char sep)
|
||||
{
|
||||
int i;
|
||||
int count;
|
||||
|
||||
i = 0;
|
||||
count = 0;
|
||||
while (str[i])
|
||||
{
|
||||
while (str[i] == sep && str[i])
|
||||
i++;
|
||||
if (str[i] != sep && str[i])
|
||||
{
|
||||
while (str[i] != sep && str[i])
|
||||
i++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
|
||||
static char *ft_strndup(const char *s, int j)
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
|
||||
i = 0;
|
||||
str = (char *)malloc((j + 1));
|
||||
if (!str)
|
||||
return (NULL);
|
||||
while (s[i] && i < j)
|
||||
{
|
||||
str[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
str[i] = '\0';
|
||||
return (str);
|
||||
}
|
||||
|
||||
static char **ext_w(char **words_array, const char *str, char sep, int size)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (j < size)
|
||||
{
|
||||
while (str[i] == sep && str[i])
|
||||
i++;
|
||||
str = str + i;
|
||||
i = 0;
|
||||
while (str[i] != sep && str[i])
|
||||
i++;
|
||||
words_array[j++] = ft_strndup(str, i);
|
||||
str = str + i;
|
||||
i = 0;
|
||||
}
|
||||
words_array[j] = 0;
|
||||
return (words_array);
|
||||
}
|
||||
|
||||
char **ft_split(char const *s, char c)
|
||||
{
|
||||
int size;
|
||||
char **words_array;
|
||||
|
||||
size = count_words(s, c);
|
||||
words_array = (char **)malloc(sizeof(char *) * (size + 1));
|
||||
if (!words_array)
|
||||
return (NULL);
|
||||
if (size == 0)
|
||||
{
|
||||
words_array[0] = NULL;
|
||||
return (words_array);
|
||||
}
|
||||
words_array = ext_w(words_array, s, c, size);
|
||||
return (words_array);
|
||||
}
|
||||
25
math/sources/operation/ft_add.c
Normal file
25
math/sources/operation/ft_add.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_add.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/27 12:27:41 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/28 14:09:12 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/ft_math.h"
|
||||
|
||||
t_error ft_add(t_number *a, t_number *b)
|
||||
{
|
||||
// t_number result;
|
||||
// t_usize index;
|
||||
|
||||
if (a == NULL || b == NULL)
|
||||
return (ERROR);
|
||||
// index = 0;
|
||||
|
||||
return (NO_ERROR);
|
||||
}
|
||||
26
math/sources/operation/ft_pow.c
Normal file
26
math/sources/operation/ft_pow.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_pow.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/04 12:14:51 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/27 14:37:29 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/ft_math.h"
|
||||
|
||||
long long int ft_pow(long long int base, long long int exponent)
|
||||
{
|
||||
(void)base;
|
||||
(void)exponent;
|
||||
return (0);
|
||||
}
|
||||
|
||||
// int main(void)
|
||||
// {
|
||||
// printf("Original: %f\n", pow(3, 3));
|
||||
// printf("HomeMade: %lld\n", ft_pow(3, 3));
|
||||
// }
|
||||
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