msvcrt: Import floor implementation from musl.
The implementation is based on floorf. Signed-off-by: Piotr Caban <piotr@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
e5ddf0e8d8
commit
29c07324c1
|
@ -1811,10 +1811,31 @@ double CDECL ceil( double x )
|
|||
|
||||
/*********************************************************************
|
||||
* floor (MSVCRT.@)
|
||||
*
|
||||
* Based on musl: src/math/floorf.c
|
||||
*/
|
||||
double CDECL floor( double x )
|
||||
{
|
||||
return unix_funcs->floor(x);
|
||||
union {double f; UINT64 i;} u = {x};
|
||||
int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff;
|
||||
UINT64 m;
|
||||
|
||||
if (e >= 52)
|
||||
return x;
|
||||
if (e >= 0) {
|
||||
m = 0x000fffffffffffffULL >> e;
|
||||
if ((u.i & m) == 0)
|
||||
return x;
|
||||
if (u.i >> 63)
|
||||
u.i += m;
|
||||
u.i &= ~m;
|
||||
} else {
|
||||
if (u.i >> 63 == 0)
|
||||
return 0;
|
||||
else if (u.i << 1)
|
||||
return -1;
|
||||
}
|
||||
return u.f;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
|
|
@ -273,14 +273,6 @@ static float CDECL unix_expm1f(float x)
|
|||
#endif
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* floor
|
||||
*/
|
||||
static double CDECL unix_floor( double x )
|
||||
{
|
||||
return floor( x );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* fma
|
||||
*/
|
||||
|
@ -703,7 +695,6 @@ static const struct unix_funcs funcs =
|
|||
unix_exp2f,
|
||||
unix_expm1,
|
||||
unix_expm1f,
|
||||
unix_floor,
|
||||
unix_fma,
|
||||
unix_fmaf,
|
||||
unix_fmod,
|
||||
|
|
|
@ -43,7 +43,6 @@ struct unix_funcs
|
|||
float (CDECL *exp2f)(float x);
|
||||
double (CDECL *expm1)(double x);
|
||||
float (CDECL *expm1f)(float x);
|
||||
double (CDECL *floor)(double x);
|
||||
double (CDECL *fma)(double x, double y, double z);
|
||||
float (CDECL *fmaf)(float x, float y, float z);
|
||||
double (CDECL *fmod)(double x, double y);
|
||||
|
|
Loading…
Reference in New Issue