fix ft_modf
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "libft.h"
|
||||
|
||||
#include <stdio.h> // tmp for printf, for float debug
|
||||
|
||||
/**
|
||||
* Splits a double into its integer and fractional parts,
|
||||
* it returns the fractional part,
|
||||
@@ -7,17 +9,17 @@
|
||||
* e.g.:
|
||||
* -3.7 → -3.0 and -0.7 (returns -0.7)
|
||||
*/
|
||||
double ft_modf(double x, double *int_part)
|
||||
double ft_modf(double x, double *store_int_part)
|
||||
{
|
||||
// extract the integer part by casting to long long
|
||||
long long integer = (long long)x;
|
||||
if (int_part != NULL)
|
||||
if (store_int_part != NULL)
|
||||
{
|
||||
*int_part = (double)integer;
|
||||
*store_int_part = (double)integer;
|
||||
}
|
||||
|
||||
// compute the fractional part
|
||||
double frac_part = x - *int_part;
|
||||
double frac_part = x - integer;
|
||||
|
||||
return frac_part;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user