From: Lukas Jiriste Date: Fri, 23 Feb 2024 08:08:45 +0000 (+0100) Subject: Add ft_min and ft_max functions for int and size_t X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=8008688f6bc3521827bf89c499954365a98efdf6;p=Libft.git Add ft_min and ft_max functions for int and size_t --- diff --git a/Makefile b/Makefile index 3fffc1f..c49039e 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,8 @@ SRCgen := ft_swap.c \ SRCmath := ft_abs.c \ ft_sgn.c \ + ft_max.c \ + ft_min.c \ SRCstr := ft_strncat_alloc.c \ ft_strcmp.c \ diff --git a/ft_math/ft_max.c b/ft_math/ft_max.c new file mode 100644 index 0000000..076c6e8 --- /dev/null +++ b/ft_math/ft_max.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_max.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/02/22 14:29:48 by ljiriste #+# #+# */ +/* Updated: 2024/02/23 08:57:26 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_math.h" +#include + +int ft_max(int a, int b) +{ + if (a > b) + return (a); + return (b); +} + +size_t ft_maxs(size_t a, size_t b) +{ + if (a > b) + return (a); + return (b); +} diff --git a/ft_math/ft_min.c b/ft_math/ft_min.c new file mode 100644 index 0000000..d09f05e --- /dev/null +++ b/ft_math/ft_min.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_min.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/02/23 08:58:39 by ljiriste #+# #+# */ +/* Updated: 2024/02/23 08:59:40 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_math.h" +#include + +int ft_min(int a, int b) +{ + if (a < b) + return (a); + return (b); +} + +size_t ft_mins(size_t a, size_t b) +{ + if (a < b) + return (a); + return (b); +} diff --git a/inc/ft_math.h b/inc/ft_math.h index 657642e..6c272f4 100644 --- a/inc/ft_math.h +++ b/inc/ft_math.h @@ -6,14 +6,22 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/09 12:19:15 by ljiriste #+# #+# */ -/* Updated: 2024/01/18 09:44:29 by ljiriste ### ########.fr */ +/* Updated: 2024/02/23 09:01:20 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_MATH_H # define FT_MATH_H +# include + int ft_abs(int n); int ft_sgn(int n); +int ft_max(int a, int b); +size_t ft_maxs(size_t a, size_t b); + +int ft_min(int a, int b); +size_t ft_mins(size_t a, size_t b); + #endif