/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/isa_defs.h>
#include "libm_inlines.h"
#ifdef _LITTLE_ENDIAN
#define LO(x) *(unsigned*)x
#else
#define HI(x) *(int*)x
#endif
#ifdef __RESTRICT
#define restrict _Restrict
#else
#define restrict
#endif
/* double hypot(double x, double y)
*
* Method :
* 1. Special cases:
* x or y is +Inf or -Inf => +Inf
* x or y is NaN => QNaN
* 2. Computes hypot(x,y):
* hypot(x,y) = m * sqrt(xnm * xnm + ynm * ynm)
* Where:
* m = max(|x|,|y|)
* xnm = x * (1/m)
* ynm = y * (1/m)
*
* Compute xnm * xnm + ynm * ynm by simulating
* muti-precision arithmetic.
*
* Accuracy:
* Maximum error observed: less than 0.872 ulp after 16.777.216.000
* results.
*/
extern double sqrt(double);
extern double fabs(double);
static const unsigned long long LCONST[] = {
0x41b0000000000000ULL, /* D2ON28 = 2 ** 28 */
0x0010000000000000ULL, /* D2ONM1022 = 2 ** -1022 */
0x7fd0000000000000ULL /* D2ONP1022 = 2 ** 1022 */
};
static void
#pragma no_inline(__vhypot_n)
{ \
if (n_n == 0) \
{ \
continue; \
} \
n--; \
break; \
}
void
{
double scl = 0;
double x, y, res;
int n_n;
while (n > 1)
{
n_n = 0;
for (; n > 1 ; n--)
{
hx0 &= 0x7fffffff;
hy0 &= 0x7fffffff;
{
j0 &= 0x7ff00000;
y = *py;
x = fabs(x);
y = fabs(y);
{
else res = x + y;
}
else
{
{
x *= D2ONM1022;
y *= D2ONM1022;
}
else RETURN (x + y)
}
}
{
j0 &= 0x7ff00000;
y = *py;
x = fabs(x);
y = fabs(y);
{
else res = x + y;
}
else
{
{
x *= D2ONM1022;
y *= D2ONM1022;
}
else RETURN (x + y)
}
}
{
y = *py;
x *= D2ONP1022;
y *= D2ONP1022;
}
n_n++;
}
if (n_n > 0)
}
if (n > 0)
{
x = *px;
y = *py;
hx0 &= 0x7fffffff;
hy0 &= 0x7fffffff;
j0 &= 0x7ff00000;
{
x = fabs(x);
y = fabs(y);
{
else res = x + y;
return;
}
else
{
{
x *= D2ONM1022;
y *= D2ONM1022;
return;
}
else
{
*pz = x + y;
return;
}
}
}
{
x *= D2ONP1022;
y *= D2ONP1022;
return;
}
x *= scl;
y *= scl;
}
}
static void
{
for(; n > 0 ; n--)
{
hx0 &= 0x7fffffff;
hy0 &= 0x7fffffff;
j0 &= 0x7ff00000;
}
}