diff --git a/srcs/ft_abs.c b/srcs/ft_abs.c index c4743a0..8fd80b5 100644 --- a/srcs/ft_abs.c +++ b/srcs/ft_abs.c @@ -1,8 +1,12 @@ #include "libft.h" +/** + * returns the absolute value of an int number + */ + int ft_abs(int n) { - if (n < 0) - n *= -1; + if (n <= 0) + n *= -1; // also works for -0 return (n); } diff --git a/srcs/ft_fabs.c b/srcs/ft_fabs.c index 45c9223..9f5cbd0 100644 --- a/srcs/ft_fabs.c +++ b/srcs/ft_fabs.c @@ -1,8 +1,12 @@ #include "libft.h" +/** + * returns the absolute value of a double number + */ + double ft_fabs(double n) { - if (n < 0) - n *= -1; + if (n <= 0) + n *= -1; // also works for -0 return (n); } diff --git a/srcs/ft_labs.c b/srcs/ft_labs.c index 2203c33..8e69a3d 100644 --- a/srcs/ft_labs.c +++ b/srcs/ft_labs.c @@ -1,8 +1,12 @@ #include "libft.h" +/** + * returns the absolute value of a long int number + */ + long int ft_labs(long int n) { - if (n < 0) - n *= -1; + if (n <= 0) + n *= -1; // also works for -0 return (n); }