Compare commits

...

1 Commits

Author SHA1 Message Date
hugogogo
45cc208f44 fix abs family for -0 value 2026-05-10 20:18:37 +02:00
3 changed files with 18 additions and 6 deletions

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}