mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-15 12:49:19 +00:00
msvcrt: Use the floor()/floorf() implementation from the bundled musl library.
With the changes from 29c07324c1
.
This commit is contained in:
parent
9db27802c3
commit
70bcaec7dc
|
@ -1426,35 +1426,6 @@ float CDECL ceilf( float x )
|
||||||
return u.f;
|
return u.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
|
||||||
* floorf (MSVCRT.@)
|
|
||||||
*
|
|
||||||
* Copied from musl: src/math/floorf.c
|
|
||||||
*/
|
|
||||||
float CDECL floorf( float x )
|
|
||||||
{
|
|
||||||
union {float f; UINT32 i;} u = {x};
|
|
||||||
int e = (int)(u.i >> 23 & 0xff) - 0x7f;
|
|
||||||
UINT32 m;
|
|
||||||
|
|
||||||
if (e >= 23)
|
|
||||||
return x;
|
|
||||||
if (e >= 0) {
|
|
||||||
m = 0x007fffff >> e;
|
|
||||||
if ((u.i & m) == 0)
|
|
||||||
return x;
|
|
||||||
if (u.i >> 31)
|
|
||||||
u.i += m;
|
|
||||||
u.i &= ~m;
|
|
||||||
} else {
|
|
||||||
if (u.i >> 31 == 0)
|
|
||||||
return 0;
|
|
||||||
else if (u.i << 1)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return u.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
|
@ -3260,35 +3231,6 @@ double CDECL ceil( double x )
|
||||||
return u.f;
|
return u.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
|
||||||
* floor (MSVCRT.@)
|
|
||||||
*
|
|
||||||
* Based on musl: src/math/floorf.c
|
|
||||||
*/
|
|
||||||
double CDECL floor( double 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(__i386__) || defined(__x86_64__)
|
#if defined(__i386__) || defined(__x86_64__)
|
||||||
static void _setfp_sse( unsigned int *cw, unsigned int cw_mask,
|
static void _setfp_sse( unsigned int *cw, unsigned int cw_mask,
|
||||||
unsigned int *sw, unsigned int sw_mask )
|
unsigned int *sw, unsigned int sw_mask )
|
||||||
|
|
|
@ -5,27 +5,27 @@
|
||||||
#elif FLT_EVAL_METHOD==2
|
#elif FLT_EVAL_METHOD==2
|
||||||
#define EPS LDBL_EPSILON
|
#define EPS LDBL_EPSILON
|
||||||
#endif
|
#endif
|
||||||
static const double_t toint = 1/EPS;
|
|
||||||
|
|
||||||
double __cdecl floor(double x)
|
double __cdecl floor(double x)
|
||||||
{
|
{
|
||||||
union {double f; uint64_t i;} u = {x};
|
union {double f; uint64_t i;} u = {x};
|
||||||
int e = u.i >> 52 & 0x7ff;
|
int e = (u.i >> 52 & 0x7ff) - 0x3ff;
|
||||||
double_t y;
|
double_t y;
|
||||||
|
|
||||||
if (e >= 0x3ff+52 || x == 0)
|
if (e >= 52)
|
||||||
return x;
|
return x;
|
||||||
/* y = int(x) - x, where int(x) is an integer neighbor of x */
|
if (e >= 0) {
|
||||||
if (u.i >> 63)
|
uint64_t m = 0x000fffffffffffffULL >> e;
|
||||||
y = x - toint + toint - x;
|
if ((u.i & m) == 0)
|
||||||
else
|
return x;
|
||||||
y = x + toint - toint - x;
|
if (u.i >> 63)
|
||||||
/* special case because of non-nearest rounding modes */
|
u.i += m;
|
||||||
if (e <= 0x3ff-1) {
|
u.i &= ~m;
|
||||||
FORCE_EVAL(y);
|
} else {
|
||||||
return u.i >> 63 ? -1 : 0;
|
if (u.i >> 63 == 0)
|
||||||
|
return 0;
|
||||||
|
if (u.i << 1)
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (y > 0)
|
return u.f;
|
||||||
return x + y - 1;
|
|
||||||
return x + y;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue