From 78f6a2d9ba8671b00a649aee9bab1ff810d450dd Mon Sep 17 00:00:00 2001 From: hugogogo Date: Wed, 6 May 2026 22:54:20 +0200 Subject: [PATCH] adding sign and abs for doubles --- Makefile | 2 ++ includes/libft.h | 2 ++ srcs/ft_abs.c | 2 +- srcs/ft_abs_f.c | 8 ++++++++ srcs/ft_sign.c | 2 +- srcs/ft_sign_f.c | 8 ++++++++ 6 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 srcs/ft_abs_f.c create mode 100644 srcs/ft_sign_f.c diff --git a/Makefile b/Makefile index 97c5179..3863b5b 100644 --- a/Makefile +++ b/Makefile @@ -120,9 +120,11 @@ SRCS = ft_memset.c \ pf_utils.c \ \ ft_abs.c \ + ft_abs_f.c \ ft_greater.c \ ft_smaller.c \ ft_sign.c \ + ft_sign_f.c \ ft_sqrt.c \ ft_free_tab.c \ \ diff --git a/includes/libft.h b/includes/libft.h index 7946cd0..83b736d 100644 --- a/includes/libft.h +++ b/includes/libft.h @@ -122,9 +122,11 @@ void ft_putnbrendl(int n); void ft_putnbrendl_fd(int n, int fd); char *ft_concat_free(char *str1, char *str2); int ft_abs(int n); +double ft_abs_f(double n); int ft_greater(int a, int b); int ft_smaller(int a, int b); int ft_sign(int i); +int ft_sign_f(double i); int ft_sqrt(int i); void ft_free_tab(char **tab); diff --git a/srcs/ft_abs.c b/srcs/ft_abs.c index 3cdb51f..c4743a0 100644 --- a/srcs/ft_abs.c +++ b/srcs/ft_abs.c @@ -1,6 +1,6 @@ #include "libft.h" -int ft_abs(int n) +int ft_abs(int n) { if (n < 0) n *= -1; diff --git a/srcs/ft_abs_f.c b/srcs/ft_abs_f.c new file mode 100644 index 0000000..4d0121a --- /dev/null +++ b/srcs/ft_abs_f.c @@ -0,0 +1,8 @@ +#include "libft.h" + +double ft_abs_f(double n) +{ + if (n < 0) + n *= -1; + return (n); +} diff --git a/srcs/ft_sign.c b/srcs/ft_sign.c index b665855..31d2e29 100644 --- a/srcs/ft_sign.c +++ b/srcs/ft_sign.c @@ -1,6 +1,6 @@ #include "libft.h" -int ft_sign(int i) +int ft_sign(int i) { if (i < 0) return (-1); diff --git a/srcs/ft_sign_f.c b/srcs/ft_sign_f.c new file mode 100644 index 0000000..141fbf0 --- /dev/null +++ b/srcs/ft_sign_f.c @@ -0,0 +1,8 @@ +#include "libft.h" + +int ft_sign_f(double i) +{ + if (i < 0) + return (-1); + return (1); +}