libc/math: fix fmod family operation

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
Petro Karashchenko 2021-12-30 21:21:45 +02:00 committed by Xiang Xiao
parent 185de258bf
commit 8462b14d4e
6 changed files with 11 additions and 17 deletions

View File

@ -43,10 +43,8 @@ double fmod(double x, double div)
{
double n0;
x /= div;
x = modf(x, &n0);
x *= div;
modf(x / div, &n0);
return x;
return x - n0 * div;
}
#endif

View File

@ -39,9 +39,7 @@ float fmodf(float x, float div)
{
float n0;
x /= div;
x = modff(x, &n0);
x *= div;
modff(x / div, &n0);
return x;
return x - n0 * div;
}

View File

@ -43,10 +43,8 @@ long double fmodl(long double x, long double div)
{
long double n0;
x /= div;
x = modfl(x, &n0);
x *= div;
modfl(x / div, &n0);
return x;
return x - n0 * div;
}
#endif

View File

@ -46,12 +46,12 @@ double modf(double x, double *iptr)
}
else if (fabs(x) < 1.0)
{
*iptr = (x * 0.0);
*iptr = 0.0;
return x;
}
else
{
*iptr = (double)(int64_t) x;
*iptr = (double)(int64_t)x;
return (x - *iptr);
}
}

View File

@ -44,7 +44,7 @@ float modff(float x, float *iptr)
}
else if (fabsf(x) < 1.0F)
{
*iptr = (x * 0.0F);
*iptr = 0.0F;
return x;
}
else

View File

@ -49,12 +49,12 @@ long double modfl(long double x, long double *iptr)
}
else if (fabsl(x) < 1.0)
{
*iptr = (x * 0.0);
*iptr = 0.0;
return x;
}
else
{
*iptr = (long double)(int64_t) x;
*iptr = (long double)(int64_t)x;
return (x - *iptr);
}
}