Module: wine Branch: master Commit: cd29cd85ab89574216872f4e181f46d79c7a1210 URL: https://gitlab.winehq.org/wine/wine/-/commit/cd29cd85ab89574216872f4e181f46d...
Author: Alexandre Julliard julliard@winehq.org Date: Thu Mar 30 18:11:34 2023 +0200
msvcrt: Use the ceil()/ceilf() implementation from the bundled musl library.
With the changes from 2a5e68ab807939b1b5b1484a189717b659b0a28e.
---
dlls/msvcrt/math.c | 58 ----------------------------------------------- libs/musl/src/math/ceil.c | 32 +++++++++++++------------- 2 files changed, 16 insertions(+), 74 deletions(-)
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c index aee19f297cc..d8563873562 100644 --- a/dlls/msvcrt/math.c +++ b/dlls/msvcrt/math.c @@ -1397,35 +1397,6 @@ float CDECL tanhf( float x ) 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
/********************************************************************* @@ -3202,35 +3173,6 @@ __int64 CDECL _abs64( __int64 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__) static void _setfp_sse( unsigned int *cw, unsigned int cw_mask, unsigned int *sw, unsigned int sw_mask ) diff --git a/libs/musl/src/math/ceil.c b/libs/musl/src/math/ceil.c index 781a90bd685..ba2a689907e 100644 --- a/libs/musl/src/math/ceil.c +++ b/libs/musl/src/math/ceil.c @@ -5,27 +5,27 @@ #elif FLT_EVAL_METHOD==2 #define EPS LDBL_EPSILON #endif -static const double_t toint = 1/EPS;
double __cdecl ceil(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 ? -0.0 : 1; - } - if (y < 0) - return x + y + 1; - return x + y; + if (e >= 0) { + uint64_t 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; + if (u.i << 1) + return 1.0; + } + return u.f; }