Commit 29c07324 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Import floor implementation from musl.

The implementation is based on floorf. Signed-off-by: 's avatarPiotr Caban <piotr@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent e5ddf0e8
......@@ -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;
}
/*********************************************************************
......
......@@ -274,14 +274,6 @@ static float CDECL unix_expm1f(float x)
}
/*********************************************************************
* floor
*/
static double CDECL unix_floor( double x )
{
return floor( x );
}
/*********************************************************************
* fma
*/
static double CDECL unix_fma( double x, double y, double z )
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment