Commit cd29cd85 authored by Alexandre Julliard's avatar Alexandre Julliard

msvcrt: Use the ceil()/ceilf() implementation from the bundled musl library.

With the changes from 2a5e68ab.
parent 70bcaec7
...@@ -1397,35 +1397,6 @@ float CDECL tanhf( float x ) ...@@ -1397,35 +1397,6 @@ float CDECL tanhf( float x )
return sign ? -t : t; return sign ? -t : t;
} }
/*********************************************************************
* ceilf (MSVCRT.@)
*
* Copied from musl: src/math/ceilf.c
*/
float CDECL ceilf( 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 == 0)
u.i += m;
u.i &= ~m;
} else {
if (u.i >> 31)
return -0.0;
else if (u.i << 1)
return 1.0;
}
return u.f;
}
#endif #endif
/********************************************************************* /*********************************************************************
...@@ -3202,35 +3173,6 @@ __int64 CDECL _abs64( __int64 n ) ...@@ -3202,35 +3173,6 @@ __int64 CDECL _abs64( __int64 n )
return n >= 0 ? n : -n; return n >= 0 ? n : -n;
} }
/*********************************************************************
* ceil (MSVCRT.@)
*
* Based on musl: src/math/ceilf.c
*/
double CDECL ceil( double x )
{
union {double f; UINT64 i;} u = {x};
int e = (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 == 0)
u.i += m;
u.i &= ~m;
} else {
if (u.i >> 63)
return -0.0;
else if (u.i << 1)
return 1.0;
}
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 @@ ...@@ -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 ceil(double x) double __cdecl ceil(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 == 0)
/* 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 ? -0.0 : 1; if (u.i >> 63)
} return -0.0;
if (y < 0) if (u.i << 1)
return x + y + 1; return 1.0;
return x + y; }
return u.f;
} }
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