/*
* 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.
*/
/* INDENT OFF */
/*
* Hypot(x, y)
* by K.C. Ng for SUN 4.0 libm, updated 3/11/2003.
* Method :
* A. When rounding is rounded-to-nearest:
* If z = x * x + y * y has error less than sqrt(2) / 2 ulp than
* sqrt(z) has error less than 1 ulp.
* So, compute sqrt(x*x+y*y) with some care as follows:
* Assume x > y > 0;
* 1. Check whether save and set rounding to round-to-nearest
* 2. if x > 2y use
* xh*xh+(y*y+((x-xh)*(x+xh))) for x*x+y*y
* where xh = x with lower 32 bits cleared; else
* 3. if x <= 2y use
* x2h*yh+((x-y)*(x-y)+(x2h*(y-yh)+(x2-x2h)*y))
* where x2 = 2*x, x2h = 2x with lower 32 bits cleared, yh = y with
* lower 32 bits chopped.
*
* B. When rounding is not rounded-to-nearest:
* The following (magic) formula will yield an error less than 1 ulp.
* z = sqrt(x * x + y * y)
* hypot(x, y) = x + (y / ((x + z) / y))
*
* NOTE: DO NOT remove parenthsis!
*
* Special cases:
* hypot(x, y) is INF if x or y is +INF or -INF; else
* hypot(x, y) is NAN if x or y is NAN.
*
* Accuracy:
* hypot(x, y) returns sqrt(x^2+y^2) with error less than 1 ulps
* (units in the last place)
*/
#include "libm.h"
static const double
/* INDENT ON */
double
hypot(double x, double y) {
/*
* Force ax = |x| ~>~ ay = |y|
*/
i = ix;
iy = i;
i = lx;
ly = i;
} else {
}
/*
* x >= 2^500 (x*x or y*y may overflow)
*/
if (nx >= 0x5f3) {
else
} else if (j > 32) { /* x >> y */
if (j <= 53)
return (ax);
}
iscale = 2;
}
/*
* y < 2^-450 (x*x or y*y may underflow)
*/
else if (ny < 0x23d) {
return (ay);
return (ax);
if (j > 53) /* x >> y */
iscale = 1;
if (nx == 0) {
return (ax);
} else
if (ny == 0) {
} else
if (j > 32) { /* x >> y */
if (j <= 53)
}
} else if (j > 32) { /* x >> y */
if (j <= 53)
}
/*
* First check rounding mode by comparing onep1u*onep1u with onep1u+twom53.
* Make sure the computation is done at run-time.
*/
} else
/* round-to-zero, positive, negative mode */
/* magic formula with less than an ulp error */
} else {
/* round-to-nearest mode */
if (w > ay) {
} else {
}
}
if (iscale > 0) {
if (iscale == 1)
else {
}
}
return (ax);
}