added bgoulard lib + made lib sources in their own directory in build/ for readability
This commit is contained in:
parent
83cc8419a0
commit
0a390934d6
457 changed files with 21807 additions and 61 deletions
18
libft_personal/src/ft_math/ft_abs.c
Normal file
18
libft_personal/src/ft_math/ft_abs.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_abs.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 23:10:52 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/26 10:21:20 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_abs(int x)
|
||||
{
|
||||
if (x < 0)
|
||||
return (-x);
|
||||
return (x);
|
||||
}
|
||||
28
libft_personal/src/ft_math/ft_align.c
Normal file
28
libft_personal/src/ft_math/ft_align.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_align.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/26 19:51:21 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/26 20:46:58 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
size_t ft_align_2(size_t size, size_t alignment)
|
||||
{
|
||||
return ((size + alignment - 1) & ~(alignment - 1));
|
||||
}
|
||||
|
||||
size_t ft_align(size_t size, size_t alignment)
|
||||
{
|
||||
if (alignment < 2)
|
||||
return (size);
|
||||
if (size % alignment == 0)
|
||||
return (size);
|
||||
size += alignment - size % alignment;
|
||||
return (size);
|
||||
}
|
||||
38
libft_personal/src/ft_math/ft_clamp.c
Normal file
38
libft_personal/src/ft_math/ft_clamp.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_torange.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/16 14:51:08 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/16 15:04:23 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_clamp(int value, int min, int max)
|
||||
{
|
||||
if (value < min)
|
||||
return (min);
|
||||
else if (value > max)
|
||||
return (max);
|
||||
return (value);
|
||||
}
|
||||
|
||||
float ft_clamp_f(float value, float min, float max)
|
||||
{
|
||||
if (value < min)
|
||||
return (min);
|
||||
else if (value > max)
|
||||
return (max);
|
||||
return (value);
|
||||
}
|
||||
|
||||
double ft_clamp_d(double value, double min, double max)
|
||||
{
|
||||
if (value < min)
|
||||
return (min);
|
||||
else if (value > max)
|
||||
return (max);
|
||||
return (value);
|
||||
}
|
||||
35
libft_personal/src/ft_math/ft_complex.c
Normal file
35
libft_personal/src/ft_math/ft_complex.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_complex.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/01 08:11:12 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/13 16:39:46 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_math.h"
|
||||
|
||||
double ft_complex_abs(t_complex nb)
|
||||
{
|
||||
return (ft_sqrt(nb.real * nb.real + nb.imaginary * nb.imaginary));
|
||||
}
|
||||
|
||||
t_complex ft_complex_addl(t_complex nb, long factor)
|
||||
{
|
||||
return ((t_complex){.real = nb.real + (double)factor,
|
||||
.imaginary = nb.imaginary + (double)factor});
|
||||
}
|
||||
|
||||
t_complex ft_complex_mull(t_complex nb, long factor)
|
||||
{
|
||||
return (ft_complex_muld(nb, (double)factor));
|
||||
}
|
||||
|
||||
t_complex ft_complex_muld(t_complex nb, double factor)
|
||||
{
|
||||
return ((t_complex){.real = nb.real * factor,
|
||||
.imaginary = nb.imaginary * factor});
|
||||
}
|
||||
49
libft_personal/src/ft_math/ft_intrange.c
Normal file
49
libft_personal/src/ft_math/ft_intrange.c
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_intrange.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/29 16:22:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/13 16:41:22 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_math.h"
|
||||
|
||||
int ft_range(int x, int min, int max, int new_max)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (max == min || new_max == 0 || min >= max)
|
||||
return (0);
|
||||
if (x <= min)
|
||||
return (0);
|
||||
if (x >= max)
|
||||
return (new_max);
|
||||
res = x - min;
|
||||
max -= min;
|
||||
return ((int)(((double)res / max) * new_max));
|
||||
}
|
||||
|
||||
float ft_range_f(float x, float min, float max, float new_max)
|
||||
{
|
||||
return ((float)ft_range_d((double)x, (double)min, (double)max, \
|
||||
(double)new_max));
|
||||
}
|
||||
|
||||
double ft_range_d(double x, double min, double max, double new_max)
|
||||
{
|
||||
double res;
|
||||
|
||||
if (max == min || new_max == 0 || min >= max)
|
||||
return (0);
|
||||
if (x <= min)
|
||||
return (0);
|
||||
if (x >= max)
|
||||
return (new_max);
|
||||
res = x - min;
|
||||
max -= min;
|
||||
return ((res / max) * new_max);
|
||||
}
|
||||
44
libft_personal/src/ft_math/ft_log.c
Normal file
44
libft_personal/src/ft_math/ft_log.c
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_log.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/23 10:09:57 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/23 18:27:33 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_ullogof(unsigned long long nbr, int base)
|
||||
{
|
||||
const unsigned long long bul = (unsigned long long)base;
|
||||
int pow;
|
||||
|
||||
pow = -1;
|
||||
while (nbr)
|
||||
{
|
||||
nbr /= bul;
|
||||
pow++;
|
||||
}
|
||||
return (pow);
|
||||
}
|
||||
|
||||
int ft_llogof(long long nbr, int base)
|
||||
{
|
||||
if (nbr <= 0)
|
||||
return (-1);
|
||||
return (ft_ullogof((unsigned long long)nbr, base));
|
||||
}
|
||||
|
||||
int ft_logof(int nbr, int base)
|
||||
{
|
||||
if (nbr <= 0)
|
||||
return (-1);
|
||||
return (ft_llogof((long long)nbr, base));
|
||||
}
|
||||
|
||||
int ft_log(int nbr)
|
||||
{
|
||||
return (ft_logof(nbr, 10));
|
||||
}
|
||||
25
libft_personal/src/ft_math/ft_minmax.c
Normal file
25
libft_personal/src/ft_math/ft_minmax.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_minmax.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/23 10:23:07 by bgoulard #+# #+# */
|
||||
/* Updated: 2023/11/23 10:35:03 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_min(int a, int b)
|
||||
{
|
||||
if (a < b)
|
||||
return (a);
|
||||
return (b);
|
||||
}
|
||||
|
||||
int ft_max(int a, int b)
|
||||
{
|
||||
if (a > b)
|
||||
return (a);
|
||||
return (b);
|
||||
}
|
||||
30
libft_personal/src/ft_math/ft_pow.c
Normal file
30
libft_personal/src/ft_math/ft_pow.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_pow.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 23:04:24 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/24 01:01:06 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
size_t ft_pow(size_t x, size_t y)
|
||||
{
|
||||
size_t res;
|
||||
|
||||
res = 1;
|
||||
if (y == 0)
|
||||
return (1);
|
||||
if (x == 0)
|
||||
return (0);
|
||||
while (y > 0)
|
||||
{
|
||||
res *= x;
|
||||
y--;
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
24
libft_personal/src/ft_math/ft_round.c
Normal file
24
libft_personal/src/ft_math/ft_round.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_round.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 23:10:18 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 23:10:36 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
double ft_round(double x)
|
||||
{
|
||||
double dec;
|
||||
double round;
|
||||
|
||||
dec = x - (int)x;
|
||||
if (dec >= 0.5)
|
||||
round = (int)x + 1;
|
||||
else
|
||||
round = (int)x;
|
||||
return (round);
|
||||
}
|
||||
29
libft_personal/src/ft_math/ft_sqrt.c
Normal file
29
libft_personal/src/ft_math/ft_sqrt.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_sqrt.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 23:00:06 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/24 09:33:30 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
// using newton's method
|
||||
double ft_sqrt(double nb)
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
|
||||
x = nb;
|
||||
if (nb <= 0)
|
||||
return (-1);
|
||||
y = 1;
|
||||
while (x - y > 0.0000001)
|
||||
{
|
||||
x = (x + y) / 2;
|
||||
y = nb / x;
|
||||
}
|
||||
return (x);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue