From: Lukas Jiriste Date: Thu, 18 Jan 2024 09:56:04 +0000 (+0100) Subject: Add ft_sgn signum function X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=a4212a0f1de2cf7553f3cde8931c90fe006f3cd4;p=Libft.git Add ft_sgn signum function --- diff --git a/Makefile b/Makefile index 431f293..3fffc1f 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ SRCDIR := ft_gen ft_math ft_str ft_mem ft_io ft_check ft_conv ft_lst ft_arr SRCgen := ft_swap.c \ SRCmath := ft_abs.c \ + ft_sgn.c \ SRCstr := ft_strncat_alloc.c \ ft_strcmp.c \ diff --git a/ft_math/ft_sgn.c b/ft_math/ft_sgn.c new file mode 100644 index 0000000..36c2a78 --- /dev/null +++ b/ft_math/ft_sgn.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sgn.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/01/18 09:41:56 by ljiriste #+# #+# */ +/* Updated: 2024/01/18 09:45:43 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_math.h" + +int ft_sgn(int n) +{ + return ((n > 0) - (n < 0)); +} + +/* +int ft_sgn(int n) +{ + if (n > 0) + return (1); + if (n < 0) + return (-1); + return (0); +} +*/ diff --git a/inc/ft_math.h b/inc/ft_math.h index 9f0f6a7..657642e 100644 --- a/inc/ft_math.h +++ b/inc/ft_math.h @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/09 12:19:15 by ljiriste #+# #+# */ -/* Updated: 2023/12/09 15:13:41 by ljiriste ### ########.fr */ +/* Updated: 2024/01/18 09:44:29 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,5 +14,6 @@ # define FT_MATH_H int ft_abs(int n); +int ft_sgn(int n); #endif