5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 */
25 /*
26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
28 */
29
30 #pragma weak __csinhl = csinhl
31
32 #include "libm.h" /* coshl/expl/fabsl/scalbnl/sincosl/sinhl/__k_cexpl */
33 #include "complex_wrapper.h"
34
35 /* INDENT OFF */
36 static const long double zero = 0.0L, half = 0.5L;
37 /* INDENT ON */
38
39 ldcomplex
40 csinhl(ldcomplex z) {
41 long double t, x, y, S, C;
42 int hx, ix, hy, iy, n;
43 ldcomplex ans;
44
45 x = LD_RE(z);
46 y = LD_IM(z);
47 hx = HI_XWORD(x);
48 ix = hx & 0x7fffffff;
49 hy = HI_XWORD(y);
50 iy = hy & 0x7fffffff;
51 x = fabsl(x);
52 y = fabsl(y);
53
54 (void) sincosl(y, &S, &C);
55 if (ix >= 0x4004e000) { /* |x| > 60 = prec/2 (14,28,34,60) */
56 if (ix >= 0x400C62E4) { /* |x| > 11356.52... ~ log(2**16384) */
57 if (ix >= 0x7fff0000) { /* |x| is inf or NaN */
58 if (y == zero) {
59 LD_RE(ans) = x;
60 LD_IM(ans) = y;
61 } else if (iy >= 0x7fff0000) {
62 LD_RE(ans) = x;
63 LD_IM(ans) = x - y;
64 } else {
65 LD_RE(ans) = C * x;
66 LD_IM(ans) = S * x;
67 }
68 } else {
69 /* return exp(x)=t*2**n */
70 t = __k_cexpl(x, &n);
71 LD_RE(ans) = scalbnl(C * t, n - 1);
72 LD_IM(ans) = scalbnl(S * t, n - 1);
73 }
74 } else {
75 t = expl(x) * half;
76 LD_RE(ans) = C * t;
77 LD_IM(ans) = S * t;
78 }
79 } else {
80 if (x == zero) { /* x = 0, return (0,S) */
81 LD_RE(ans) = zero;
82 LD_IM(ans) = S;
83 } else {
84 LD_RE(ans) = C * sinhl(x);
85 LD_IM(ans) = S * coshl(x);
86 }
87 }
88 if (hx < 0)
89 LD_RE(ans) = -LD_RE(ans);
90 if (hy < 0)
91 LD_IM(ans) = -LD_IM(ans);
92 return (ans);
93 }
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 */
25
26 /*
27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
29 */
30
31 #pragma weak __csinhl = csinhl
32
33 #include "libm.h" /* coshl/expl/fabsl/scalbnl/sincosl/sinhl/__k_cexpl */
34 #include "complex_wrapper.h"
35
36 static const long double zero = 0.0L, half = 0.5L;
37
38
39 ldcomplex
40 csinhl(ldcomplex z)
41 {
42 long double t, x, y, S, C;
43 int hx, ix, hy, iy, n;
44 ldcomplex ans;
45
46 x = LD_RE(z);
47 y = LD_IM(z);
48 hx = HI_XWORD(x);
49 ix = hx & 0x7fffffff;
50 hy = HI_XWORD(y);
51 iy = hy & 0x7fffffff;
52 x = fabsl(x);
53 y = fabsl(y);
54
55 (void) sincosl(y, &S, &C);
56
57 if (ix >= 0x4004e000) { /* |x| > 60 = prec/2 (14,28,34,60) */
58 if (ix >= 0x400C62E4) { /* |x| > 11356.52... ~ log(2**16384) */
59 if (ix >= 0x7fff0000) { /* |x| is inf or NaN */
60 if (y == zero) {
61 LD_RE(ans) = x;
62 LD_IM(ans) = y;
63 } else if (iy >= 0x7fff0000) {
64 LD_RE(ans) = x;
65 LD_IM(ans) = x - y;
66 } else {
67 LD_RE(ans) = C * x;
68 LD_IM(ans) = S * x;
69 }
70 } else {
71 /* return exp(x)=t*2**n */
72 t = __k_cexpl(x, &n);
73 LD_RE(ans) = scalbnl(C * t, n - 1);
74 LD_IM(ans) = scalbnl(S * t, n - 1);
75 }
76 } else {
77 t = expl(x) * half;
78 LD_RE(ans) = C * t;
79 LD_IM(ans) = S * t;
80 }
81 } else {
82 if (x == zero) { /* x = 0, return (0,S) */
83 LD_RE(ans) = zero;
84 LD_IM(ans) = S;
85 } else {
86 LD_RE(ans) = C * sinhl(x);
87 LD_IM(ans) = S * coshl(x);
88 }
89 }
90
91 if (hx < 0)
92 LD_RE(ans) = -LD_RE(ans);
93
94 if (hy < 0)
95 LD_IM(ans) = -LD_IM(ans);
96
97 return (ans);
98 }
|