msvcrt: Import modf implementation from musl.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2021-05-18 19:08:37 +02:00 committed by Alexandre Julliard
parent bc5f28888c
commit 9984a5d661
3 changed files with 31 additions and 11 deletions

View File

@ -2000,10 +2000,40 @@ double CDECL frexp( double x, int *exp )
/*********************************************************************
* modf (MSVCRT.@)
*
* Copied from musl: src/math/modf.c
*/
double CDECL modf( double x, double *iptr )
{
return unix_funcs->modf( x, iptr );
union {double f; UINT64 i;} u = {x};
UINT64 mask;
int e = (u.i >> 52 & 0x7ff) - 0x3ff;
/* no fractional part */
if (e >= 52) {
*iptr = x;
if (e == 0x400 && u.i << 12 != 0) /* nan */
return x;
u.i &= 1ULL << 63;
return u.f;
}
/* no integral part*/
if (e < 0) {
u.i &= 1ULL << 63;
*iptr = u.f;
return x;
}
mask = -1ULL >> 12 >> e;
if ((u.i & mask) == 0) {
*iptr = x;
u.i &= 1ULL << 63;
return u.f;
}
u.i &= ~mask;
*iptr = u.f;
return x - u.f;
}
/**********************************************************************

View File

@ -459,14 +459,6 @@ static float CDECL unix_logbf( float x )
return logbf( x );
}
/*********************************************************************
* modf
*/
static double CDECL unix_modf( double x, double *iptr )
{
return modf( x, iptr );
}
/*********************************************************************
* modff
*/
@ -674,7 +666,6 @@ static const struct unix_funcs funcs =
unix_log2f,
unix_logb,
unix_logbf,
unix_modf,
unix_modff,
unix_pow,
unix_powf,

View File

@ -62,7 +62,6 @@ struct unix_funcs
float (CDECL *log2f)(float x);
double (CDECL *logb)(double x);
float (CDECL *logbf)(float x);
double (CDECL *modf)(double x, double *iptr);
float (CDECL *modff)(float x, float *iptr);
double (CDECL *pow)(double x, double y);
float (CDECL *powf)(float x, float y);