4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
30 #pragma weak __csqrtl = csqrtl
32 #include "libm.h" /* fabsl/isinfl/sqrtl */
33 #include "complex_wrapper.h"
34 #include "longdouble.h"
37 static const long double
38 twom9001
= 2.6854002716003034957421765100615693043656e-2710L,
39 twom4500
= 2.3174987687592429423263242862381544149252e-1355L,
40 two8999
= 9.3095991180122343502582347372163290310934e+2708L,
41 two4500
= 4.3149968987270974283777803545571722250806e+1354L,
50 long double x
, y
, t
, ax
, ay
;
51 int n
, ix
, iy
, hx
, hy
;
61 if (ix
>= 0x7fff0000 || iy
>= 0x7fff0000) {
62 /* x or y is Inf or NaN */
64 LD_IM(ans
) = LD_RE(ans
) = ay
;
68 LD_IM(ans
) = ay
* zero
;
70 LD_RE(ans
) = ay
* zero
;
74 LD_IM(ans
) = LD_RE(ans
) = ax
+ ay
;
75 } else if (y
== zero
) {
77 LD_RE(ans
) = sqrtl(ax
);
80 LD_IM(ans
) = sqrtl(ax
);
83 } else if (ix
>= iy
) {
85 #if defined(__x86) /* 64 significant bits */
87 #else /* 113 significant bits */
91 else if (ix
>= 0x5f3f0000) { /* x > 2**8000 */
94 t
= two4500
* sqrtl(ax
+ sqrtl(ax
* ax
+ y
* y
));
95 } else if (iy
<= 0x20bf0000) { /* y < 2**-8000 */
98 t
= twom4500
* sqrtl(ax
+ sqrtl(ax
* ax
+ y
* y
));
100 t
= sqrtl(half
* (ax
+ sqrtl(ax
* ax
+ y
* y
)));
104 LD_IM(ans
) = ay
/ (t
+ t
);
107 LD_RE(ans
) = ay
/ (t
+ t
);
111 #if defined(__x86) /* 64 significant bits */
112 if (n
>= 35) { /* } */
113 #else /* 113 significant bits */
117 t
= sqrtl(half
* ay
);
118 else if (iy
>= 0x7ffe0000)
119 t
= sqrtl(half
* ay
+ half
* ax
);
120 else if (ix
<= 0x00010000)
121 t
= half
* (sqrtl(two
* (ax
+ ay
)));
123 t
= sqrtl(half
* (ax
+ ay
));
124 } else if (iy
>= 0x5f3f0000) { /* y > 2**8000 */
127 t
= two4500
* sqrtl(ax
+ sqrtl(ax
* ax
+ y
* y
));
128 } else if (ix
<= 0x20bf0000) {
131 t
= twom4500
* sqrtl(ax
+ sqrtl(ax
* ax
+ y
* y
));
133 t
= sqrtl(half
* (ax
+ sqrtl(ax
* ax
+ y
* y
)));
137 LD_IM(ans
) = ay
/ (t
+ t
);
140 LD_RE(ans
) = ay
/ (t
+ t
);
144 LD_IM(ans
) = -LD_IM(ans
);