1
0
mirror of https://github.com/wine-mirror/wine synced 2024-07-09 04:16:08 +00:00

msvcrt: Use the floor()/floorf() implementation from the bundled musl library.

With the changes from 29c07324c1.
This commit is contained in:
Alexandre Julliard 2023-03-30 18:14:13 +02:00
parent 9db27802c3
commit 70bcaec7dc
2 changed files with 15 additions and 73 deletions

View File

@ -1426,35 +1426,6 @@ float CDECL ceilf( float x )
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
/*********************************************************************
@ -3260,35 +3231,6 @@ double CDECL ceil( double x )
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__)
static void _setfp_sse( unsigned int *cw, unsigned int cw_mask,
unsigned int *sw, unsigned int sw_mask )

View File

@ -5,27 +5,27 @@
#elif FLT_EVAL_METHOD==2
#define EPS LDBL_EPSILON
#endif
static const double_t toint = 1/EPS;
double __cdecl floor(double 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;
if (e >= 0x3ff+52 || x == 0)
if (e >= 52)
return x;
/* y = int(x) - x, where int(x) is an integer neighbor of x */
if (u.i >> 63)
y = x - toint + toint - x;
else
y = x + toint - toint - x;
/* special case because of non-nearest rounding modes */
if (e <= 0x3ff-1) {
FORCE_EVAL(y);
return u.i >> 63 ? -1 : 0;
if (e >= 0) {
uint64_t 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;
if (u.i << 1)
return -1;
}
if (y > 0)
return x + y - 1;
return x + y;
return u.f;
}