fix abs family for -0 value
This commit is contained in:
@@ -1,8 +1,12 @@
|
|||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the absolute value of an int number
|
||||||
|
*/
|
||||||
|
|
||||||
int ft_abs(int n)
|
int ft_abs(int n)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n <= 0)
|
||||||
n *= -1;
|
n *= -1; // also works for -0
|
||||||
return (n);
|
return (n);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the absolute value of a double number
|
||||||
|
*/
|
||||||
|
|
||||||
double ft_fabs(double n)
|
double ft_fabs(double n)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n <= 0)
|
||||||
n *= -1;
|
n *= -1; // also works for -0
|
||||||
return (n);
|
return (n);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the absolute value of a long int number
|
||||||
|
*/
|
||||||
|
|
||||||
long int ft_labs(long int n)
|
long int ft_labs(long int n)
|
||||||
{
|
{
|
||||||
if (n < 0)
|
if (n <= 0)
|
||||||
n *= -1;
|
n *= -1; // also works for -0
|
||||||
return (n);
|
return (n);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user