Commit 15b50e98 authored by Alexandre Julliard's avatar Alexandre Julliard

msvcrt: Use the hypot()/hypotf() implementation from the bundled musl library.

parent 406c583c
......@@ -4599,107 +4599,6 @@ double CDECL _logb(double x)
return __ilogb(x);
}
static void sq(double *hi, double *lo, double x)
{
double xh, xl, xc;
xc = x * (0x1p27 + 1);
xh = x - xc + xc;
xl = x - xh;
*hi = x * x;
*lo = xh * xh - *hi + 2 * xh * xl + xl * xl;
}
/*********************************************************************
* _hypot (MSVCRT.@)
*
* Copied from musl: src/math/hypot.c
*/
double CDECL _hypot(double x, double y)
{
UINT64 ux = *(UINT64*)&x, uy = *(UINT64*)&y, ut;
double hx, lx, hy, ly, z;
int ex, ey;
/* arrange |x| >= |y| */
ux &= -1ULL >> 1;
uy &= -1ULL >> 1;
if (ux < uy) {
ut = ux;
ux = uy;
uy = ut;
}
/* special cases */
ex = ux >> 52;
ey = uy >> 52;
x = *(double*)&ux;
y = *(double*)&uy;
/* note: hypot(inf,nan) == inf */
if (ey == 0x7ff)
return y;
if (ex == 0x7ff || uy == 0)
return x;
/* note: hypot(x,y) ~= x + y*y/x/2 with inexact for small y/x */
/* 64 difference is enough for ld80 double_t */
if (ex - ey > 64)
return x + y;
/* precise sqrt argument in nearest rounding mode without overflow */
/* xh*xh must not overflow and xl*xl must not underflow in sq */
z = 1;
if (ex > 0x3ff + 510) {
z = 0x1p700;
x *= 0x1p-700;
y *= 0x1p-700;
} else if (ey < 0x3ff - 450) {
z = 0x1p-700;
x *= 0x1p700;
y *= 0x1p700;
}
sq(&hx, &lx, x);
sq(&hy, &ly, y);
return z * sqrt(ly + lx + hy + hx);
}
/*********************************************************************
* _hypotf (MSVCRT.@)
*
* Copied from musl: src/math/hypotf.c
*/
float CDECL _hypotf(float x, float y)
{
UINT32 ux = *(UINT32*)&x, uy = *(UINT32*)&y, ut;
float z;
ux &= -1U >> 1;
uy &= -1U >> 1;
if (ux < uy) {
ut = ux;
ux = uy;
uy = ut;
}
x = *(float*)&ux;
y = *(float*)&uy;
if (uy == 0xff << 23)
return y;
if (ux >= 0xff << 23 || uy == 0 || ux - uy >= 25 << 23)
return x + y;
z = 1;
if (ux >= (0x7f + 60) << 23) {
z = 0x1p90f;
x *= 0x1p-90f;
y *= 0x1p-90f;
} else if (uy < (0x7f - 60) << 23) {
z = 0x1p-90f;
x *= 0x1p90f;
y *= 0x1p90f;
}
return z * sqrtf((double)x * x + (double)y * y);
}
/*********************************************************************
* ceil (MSVCRT.@)
*
......
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