/*
* 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.
*/
/*
* long double hypotl(long double x, long double y);
* Method :
* 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. save and set rounding to round-to-nearest
* 2. if x > 2y use
* x1*x1+(y*y+(x2*(x+x2))) for x*x+y*y
* where x1 = x with lower 64 bits cleared, x2 = x-x1; else
* 3. if x <= 2y use
* t1*y1+((x-y)*(x-y)+(t1*y2+t2*y))
* where t1 = 2x with lower 64 bits cleared, t2 = 2x-t1, y1= y with
* lower 64 bits chopped, y2 = y-y1.
*
* 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"
#include "longdouble.h"
long double
hypotl(long double x, long double y) {
if ((*(int *) &one) != 0) { /* determine word ordering */
n0 = 0;
n1 = 1;
n2 = 2;
n3 = 3;
} else {
n0 = 3;
n1 = 2;
n2 = 1;
n3 = 0;
}
k = 0x7fff0000;
w = x;
x = y;
y = w;
} /* force x > y */
return (x + y); /* x/y >= 2**116 */
/* save and set RD to Rounding to nearest */
w = x - y;
if (w > y) {
} else {
x = x + x;
}
if (rd != fp_nearest)
return (x);
} else {
if (isinfl(x))
t2 = x;
else if (isinfl(y))
t2 = y;
else
t2 = x + y; /* invalid if x or y is sNaN */
return (t2);
}
if (ny == 0) {
return (x + y);
x *= t1;
y *= t1;
}
j = nx - 0x3fff0000;
}
}