From: Alexandre Julliard julliard@winehq.org
--- dlls/msvcrt/math.c | 169 ----------------------------------- libs/musl/src/math/remquo.c | 2 + libs/musl/src/math/remquof.c | 2 + 3 files changed, 4 insertions(+), 169 deletions(-)
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c index 94da43ec3f6..0c84dc23c8d 100644 --- a/dlls/msvcrt/math.c +++ b/dlls/msvcrt/math.c @@ -8994,175 +8994,6 @@ float CDECL remainderf(float x, float y) return remquof(x, y, &q); }
-/********************************************************************* - * remquo (MSVCR120.@) - * - * Copied from musl: src/math/remquo.c - */ -double CDECL remquo(double x, double y, int *quo) -{ - UINT64 uxi = *(UINT64*)&x; - UINT64 uyi = *(UINT64*)&y; - int ex = uxi >> 52 & 0x7ff; - int ey = uyi >> 52 & 0x7ff; - int sx = uxi >> 63; - int sy = uyi >> 63; - UINT32 q; - UINT64 i; - - *quo = 0; - if (y == 0 || isinf(x)) *_errno() = EDOM; - if (uyi << 1 == 0 || isnan(y) || ex == 0x7ff) - return (x * y) / (x * y); - if (uxi << 1 == 0) - return x; - - /* normalize x and y */ - if (!ex) { - for (i = uxi << 12; i >> 63 == 0; ex--, i <<= 1); - uxi <<= -ex + 1; - } else { - uxi &= -1ULL >> 12; - uxi |= 1ULL << 52; - } - if (!ey) { - for (i = uyi << 12; i >> 63 == 0; ey--, i <<= 1); - uyi <<= -ey + 1; - } else { - uyi &= -1ULL >> 12; - uyi |= 1ULL << 52; - } - - q = 0; - if (ex < ey) { - if (ex+1 == ey) - goto end; - return x; - } - - /* x mod y */ - for (; ex > ey; ex--) { - i = uxi - uyi; - if (i >> 63 == 0) { - uxi = i; - q++; - } - uxi <<= 1; - q <<= 1; - } - i = uxi - uyi; - if (i >> 63 == 0) { - uxi = i; - q++; - } - if (uxi == 0) - ex = -60; - else - for (; uxi >> 52 == 0; uxi <<= 1, ex--); -end: - /* scale result and decide between |x| and |x|-|y| */ - if (ex > 0) { - uxi -= 1ULL << 52; - uxi |= (UINT64)ex << 52; - } else { - uxi >>= -ex + 1; - } - x = *(double*)&uxi; - if (sy) - y = -y; - if (ex == ey || (ex + 1 == ey && (2 * x > y || (2 * x == y && q % 2)))) { - x -= y; - q++; - } - q &= 0x7fffffff; - *quo = sx ^ sy ? -(int)q : (int)q; - return sx ? -x : x; -} - -/********************************************************************* - * remquof (MSVCR120.@) - * - * Copied from musl: src/math/remquof.c - */ -float CDECL remquof(float x, float y, int *quo) -{ - UINT32 uxi = *(UINT32*)&x; - UINT32 uyi = *(UINT32*)&y; - int ex = uxi >> 23 & 0xff; - int ey = uyi >> 23 & 0xff; - int sx = uxi >> 31; - int sy = uyi>> 31; - UINT32 q, i; - - *quo = 0; - if (y == 0 || isinf(x)) *_errno() = EDOM; - if (uyi << 1 == 0 || isnan(y) || ex == 0xff) - return (x * y) / (x * y); - if (uxi << 1 == 0) - return x; - - /* normalize x and y */ - if (!ex) { - for (i = uxi << 9; i >> 31 == 0; ex--, i <<= 1); - uxi <<= -ex + 1; - } else { - uxi &= -1U >> 9; - uxi |= 1U << 23; - } - if (!ey) { - for (i = uyi << 9; i >> 31 == 0; ey--, i <<= 1); - uyi <<= -ey + 1; - } else { - uyi &= -1U >> 9; - uyi |= 1U << 23; - } - - q = 0; - if (ex < ey) { - if (ex + 1 == ey) - goto end; - return x; - } - - /* x mod y */ - for (; ex > ey; ex--) { - i = uxi - uyi; - if (i >> 31 == 0) { - uxi = i; - q++; - } - uxi <<= 1; - q <<= 1; - } - i = uxi - uyi; - if (i >> 31 == 0) { - uxi = i; - q++; - } - if (uxi == 0) - ex = -30; - else - for (; uxi >> 23 == 0; uxi <<= 1, ex--); -end: - /* scale result and decide between |x| and |x|-|y| */ - if (ex > 0) { - uxi -= 1U << 23; - uxi |= (UINT32)ex << 23; - } else { - uxi >>= -ex + 1; - } - x = *(float*)&uxi; - if (sy) - y = -y; - if (ex == ey || (ex + 1 == ey && (2 * x > y || (2 * x == y && q % 2)))) { - x -= y; - q++; - } - q &= 0x7fffffff; - *quo = sx ^ sy ? -(int)q : (int)q; - return sx ? -x : x; -} - /* sin(pi*x) assuming x > 2^-100, if sin(pi*x)==0 the sign is arbitrary */ static double sin_pi(double x) { diff --git a/libs/musl/src/math/remquo.c b/libs/musl/src/math/remquo.c index 6ba88688623..04bdce5027f 100644 --- a/libs/musl/src/math/remquo.c +++ b/libs/musl/src/math/remquo.c @@ -1,5 +1,6 @@ #include <math.h> #include <stdint.h> +#include "libm.h"
double __cdecl remquo(double x, double y, int *quo) { @@ -13,6 +14,7 @@ double __cdecl remquo(double x, double y, int *quo) uint64_t uxi = ux.i;
*quo = 0; + if (y == 0 || isinf(x)) errno = EDOM; if (uy.i<<1 == 0 || isnan(y) || ex == 0x7ff) return (x*y)/(x*y); if (ux.i<<1 == 0) diff --git a/libs/musl/src/math/remquof.c b/libs/musl/src/math/remquof.c index cd3bde759a8..26d48091db0 100644 --- a/libs/musl/src/math/remquof.c +++ b/libs/musl/src/math/remquof.c @@ -1,5 +1,6 @@ #include <math.h> #include <stdint.h> +#include "libm.h"
float __cdecl remquof(float x, float y, int *quo) { @@ -13,6 +14,7 @@ float __cdecl remquof(float x, float y, int *quo) uint32_t uxi = ux.i;
*quo = 0; + if (y == 0 || isinf(x)) errno = EDOM; if (uy.i<<1 == 0 || isnan(y) || ex == 0xff) return (x*y)/(x*y); if (ux.i<<1 == 0)