Commit 554e7aee authored by Alexandre Julliard's avatar Alexandre Julliard

msvcrt: Use the rint()/rintf() implementation from the bundled musl library.

parent c26fd262
...@@ -2334,9 +2334,9 @@ ...@@ -2334,9 +2334,9 @@
@ cdecl remquol(double double ptr) remquo @ cdecl remquol(double double ptr) remquo
@ cdecl rename(str str) @ cdecl rename(str str)
@ cdecl rewind(ptr) @ cdecl rewind(ptr)
@ cdecl rint(double) @ cdecl rint(double) MSVCRT_rint
@ cdecl rintf(float) @ cdecl rintf(float)
@ cdecl rintl(double) rint @ cdecl rintl(double) MSVCRT_rint
@ cdecl round(double) @ cdecl round(double)
@ cdecl roundf(float) @ cdecl roundf(float)
@ cdecl roundl(double) round @ cdecl roundl(double) round
......
...@@ -953,37 +953,6 @@ double CDECL atan( double x ) ...@@ -953,37 +953,6 @@ double CDECL atan( double x )
return sign ? -z : z; return sign ? -z : z;
} }
/*********************************************************************
* rint (MSVCR120.@)
*
* Copied from musl: src/math/rint.c
*/
double CDECL rint(double x)
{
static const double toint = 1 / DBL_EPSILON;
ULONGLONG llx = *(ULONGLONG*)&x;
int e = llx >> 52 & 0x7ff;
int s = llx >> 63;
unsigned cw;
double y;
if (e >= 0x3ff+52)
return x;
cw = _controlfp(0, 0);
if ((cw & _MCW_PC) != _PC_53)
_controlfp(_PC_53, _MCW_PC);
if (s)
y = fp_barrier(x - toint) + toint;
else
y = fp_barrier(x + toint) - toint;
if ((cw & _MCW_PC) != _PC_53)
_controlfp(cw, _MCW_PC);
if (y == 0)
return s ? -0.0 : 0;
return y;
}
/* Copied from musl: src/math/exp_data.c */ /* Copied from musl: src/math/exp_data.c */
static const UINT64 exp_T[] = { static const UINT64 exp_T[] = {
0x0ULL, 0x3ff0000000000000ULL, 0x0ULL, 0x3ff0000000000000ULL,
...@@ -2568,6 +2537,23 @@ int CDECL _isnan(double num) ...@@ -2568,6 +2537,23 @@ int CDECL _isnan(double num)
#if _MSVCR_VER>=120 #if _MSVCR_VER>=120
/********************************************************************* /*********************************************************************
* rint (MSVCR120.@)
*/
double CDECL MSVCRT_rint(double x)
{
unsigned cw;
double y;
cw = _controlfp(0, 0);
if ((cw & _MCW_PC) != _PC_53)
_controlfp(_PC_53, _MCW_PC);
y = rint(x);
if ((cw & _MCW_PC) != _PC_53)
_controlfp(cw, _MCW_PC);
return y;
}
/*********************************************************************
* _nearbyint (MSVCR120.@) * _nearbyint (MSVCR120.@)
* *
* Based on musl: src/math/nearbyteint.c * Based on musl: src/math/nearbyteint.c
...@@ -2585,7 +2571,7 @@ double CDECL nearbyint(double x) ...@@ -2585,7 +2571,7 @@ double CDECL nearbyint(double x)
cw |= _EM_INEXACT; cw |= _EM_INEXACT;
_setfp(&cw, _EM_INEXACT, NULL, 0); _setfp(&cw, _EM_INEXACT, NULL, 0);
} }
x = rint(x); x = MSVCRT_rint(x);
if (update_cw || update_sw) if (update_cw || update_sw)
{ {
sw = 0; sw = 0;
...@@ -3512,38 +3498,13 @@ void __cdecl __libm_sse2_sqrt_precise(void) ...@@ -3512,38 +3498,13 @@ void __cdecl __libm_sse2_sqrt_precise(void)
#if _MSVCR_VER>=120 #if _MSVCR_VER>=120
/********************************************************************* /*********************************************************************
* rintf (MSVCR120.@)
*
* Copied from musl: src/math/rintf.c
*/
float CDECL rintf(float x)
{
static const float toint = 1 / FLT_EPSILON;
unsigned int ix = *(unsigned int*)&x;
int e = ix >> 23 & 0xff;
int s = ix >> 31;
float y;
if (e >= 0x7f + 23)
return x;
if (s)
y = fp_barrierf(x - toint) + toint;
else
y = fp_barrierf(x + toint) - toint;
if (y == 0)
return s ? -0.0f : 0.0f;
return y;
}
/*********************************************************************
* lrint (MSVCR120.@) * lrint (MSVCR120.@)
*/ */
__msvcrt_long CDECL lrint(double x) __msvcrt_long CDECL lrint(double x)
{ {
double d; double d;
d = rint(x); d = MSVCRT_rint(x);
if ((d < 0 && d != (double)(__msvcrt_long)d) if ((d < 0 && d != (double)(__msvcrt_long)d)
|| (d >= 0 && d != (double)(__msvcrt_ulong)d)) { || (d >= 0 && d != (double)(__msvcrt_ulong)d)) {
*_errno() = EDOM; *_errno() = EDOM;
...@@ -3575,7 +3536,7 @@ __int64 CDECL llrint(double x) ...@@ -3575,7 +3536,7 @@ __int64 CDECL llrint(double x)
{ {
double d; double d;
d = rint(x); d = MSVCRT_rint(x);
if ((d < 0 && d != (double)(__int64)d) if ((d < 0 && d != (double)(__int64)d)
|| (d >= 0 && d != (double)(unsigned __int64)d)) { || (d >= 0 && d != (double)(unsigned __int64)d)) {
*_errno() = EDOM; *_errno() = EDOM;
......
...@@ -1758,9 +1758,9 @@ ...@@ -1758,9 +1758,9 @@
@ cdecl _o_remquol(double double ptr) remquo @ cdecl _o_remquol(double double ptr) remquo
@ cdecl _o_rename(str str) rename @ cdecl _o_rename(str str) rename
@ cdecl _o_rewind(ptr) rewind @ cdecl _o_rewind(ptr) rewind
@ cdecl _o_rint(double) rint @ cdecl _o_rint(double) MSVCRT_rint
@ cdecl _o_rintf(float) rintf @ cdecl _o_rintf(float) rintf
@ cdecl _o_rintl(double) rint @ cdecl _o_rintl(double) MSVCRT_rint
@ cdecl _o_round(double) round @ cdecl _o_round(double) round
@ cdecl _o_roundf(float) roundf @ cdecl _o_roundf(float) roundf
@ cdecl _o_roundl(double) round @ cdecl _o_roundl(double) round
...@@ -2471,9 +2471,9 @@ ...@@ -2471,9 +2471,9 @@
@ cdecl remquol(double double ptr) remquo @ cdecl remquol(double double ptr) remquo
@ cdecl rename(str str) @ cdecl rename(str str)
@ cdecl rewind(ptr) @ cdecl rewind(ptr)
@ cdecl rint(double) @ cdecl rint(double) MSVCRT_rint
@ cdecl rintf(float) @ cdecl rintf(float)
@ cdecl rintl(double) rint @ cdecl rintl(double) MSVCRT_rint
@ cdecl round(double) @ cdecl round(double)
@ cdecl roundf(float) @ cdecl roundf(float)
@ cdecl roundl(double) round @ cdecl roundl(double) round
......
...@@ -20,9 +20,9 @@ double __cdecl rint(double x) ...@@ -20,9 +20,9 @@ double __cdecl rint(double x)
if (e >= 0x3ff+52) if (e >= 0x3ff+52)
return x; return x;
if (s) if (s)
y = x - toint + toint; y = fp_barrier(x - toint) + toint;
else else
y = x + toint - toint; y = fp_barrier(x + toint) - toint;
if (y == 0) if (y == 0)
return s ? -0.0 : 0; return s ? -0.0 : 0;
return y; return y;
......
...@@ -22,9 +22,9 @@ float __cdecl rintf(float x) ...@@ -22,9 +22,9 @@ float __cdecl rintf(float x)
if (e >= 0x7f+23) if (e >= 0x7f+23)
return x; return x;
if (s) if (s)
y = x - toint + toint; y = fp_barrierf(x - toint) + toint;
else else
y = x + toint - toint; y = fp_barrierf(x + toint) - toint;
if (y == 0) if (y == 0)
return s ? -0.0f : 0.0f; return s ? -0.0f : 0.0f;
return y; return 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