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 __csinh = csinh
31
32 /* INDENT OFF */
33 /*
34 * dcomplex csinh(dcomplex z);
35 *
36 * z -z x -x
37 * e - e e (cos(y)+i*sin(y)) - e (cos(-y)+i*sin(-y))
38 * sinh z = -------------- = ---------------------------------------------
39 * 2 2
40 * x -x x -x
41 * cos(y) ( e - e ) + i*sin(y) (e + e )
42 * = --------------------------------------------
43 * 2
44 *
45 * = cos(y) sinh(x) + i sin(y) cosh(x)
46 *
47 * Implementation Note
48 * -------------------
49 *
50 * |x| -|x| |x| -2|x| -2|x| -P-4
51 * Note that e +- e = e ( 1 +- e ). If e < 2 , where
52 *
56 *
57 * z
58 * e
59 * sinh z = ----- if |x| >= (P/2 + 2)*ln2
60 * 2
61 *
62 * EXCEPTION (conform to ISO/IEC 9899:1999(E)):
63 * csinh(0,0)=(0,0)
64 * csinh(0,inf)=(+-0,NaN)
65 * csinh(0,NaN)=(+-0,NaN)
66 * csinh(x,inf) = (NaN,NaN) for finite positive x
67 * csinh(x,NaN) = (NaN,NaN) for finite non-zero x
68 * csinh(inf,0) = (inf, 0)
69 * csinh(inf,y) = (inf*cos(y),inf*sin(y)) for positive finite y
70 * csinh(inf,inf) = (+-inf,NaN)
71 * csinh(inf,NaN) = (+-inf,NaN)
72 * csinh(NaN,0) = (NaN,0)
73 * csinh(NaN,y) = (NaN,NaN) for non-zero y
74 * csinh(NaN,NaN) = (NaN,NaN)
75 */
76 /* INDENT ON */
77
78 #include "libm.h" /* cosh/exp/fabs/scalbn/sinh/sincos/__k_cexp */
79 #include "complex_wrapper.h"
80
81 dcomplex
82 csinh(dcomplex z) {
83 double t, x, y, S, C;
84 int hx, ix, lx, hy, iy, ly, n;
85 dcomplex ans;
86
87 x = D_RE(z);
88 y = D_IM(z);
89 hx = HI_WORD(x);
90 lx = LO_WORD(x);
91 ix = hx & 0x7fffffff;
92 hy = HI_WORD(y);
93 ly = LO_WORD(y);
94 iy = hy & 0x7fffffff;
95 x = fabs(x);
96 y = fabs(y);
97
98 (void) sincos(y, &S, &C);
99 if (ix >= 0x403c0000) { /* |x| > 28 = prec/2 (14,28,34,60) */
100 if (ix >= 0x40862E42) { /* |x| > 709.78... ~ log(2**1024) */
101 if (ix >= 0x7ff00000) { /* |x| is inf or NaN */
102 if ((iy | ly) == 0) {
103 D_RE(ans) = x;
104 D_IM(ans) = y;
105 } else if (iy >= 0x7ff00000) {
106 D_RE(ans) = x;
107 D_IM(ans) = x - y;
108 } else {
109 D_RE(ans) = C * x;
110 D_IM(ans) = S * x;
111 }
112 } else {
113 /* return exp(x)=t*2**n */
114 t = __k_cexp(x, &n);
115 D_RE(ans) = scalbn(C * t, n - 1);
116 D_IM(ans) = scalbn(S * t, n - 1);
117 }
118 } else {
119 t = exp(x) * 0.5;
120 D_RE(ans) = C * t;
121 D_IM(ans) = S * t;
122 }
123 } else {
124 if ((ix | lx) == 0) { /* x = 0, return (0,S) */
125 D_RE(ans) = 0.0;
126 D_IM(ans) = S;
127 } else {
128 D_RE(ans) = C * sinh(x);
129 D_IM(ans) = S * cosh(x);
130 }
131 }
132 if (hx < 0)
133 D_RE(ans) = -D_RE(ans);
134 if (hy < 0)
135 D_IM(ans) = -D_IM(ans);
136 return (ans);
137 }
|
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 __csinh = csinh
32
33
34 /*
35 * dcomplex csinh(dcomplex z);
36 *
37 * z -z x -x
38 * e - e e (cos(y)+i*sin(y)) - e (cos(-y)+i*sin(-y))
39 * sinh z = -------------- = ---------------------------------------------
40 * 2 2
41 * x -x x -x
42 * cos(y) ( e - e ) + i*sin(y) (e + e )
43 * = --------------------------------------------
44 * 2
45 *
46 * = cos(y) sinh(x) + i sin(y) cosh(x)
47 *
48 * Implementation Note
49 * -------------------
50 *
51 * |x| -|x| |x| -2|x| -2|x| -P-4
52 * Note that e +- e = e ( 1 +- e ). If e < 2 , where
53 *
57 *
58 * z
59 * e
60 * sinh z = ----- if |x| >= (P/2 + 2)*ln2
61 * 2
62 *
63 * EXCEPTION (conform to ISO/IEC 9899:1999(E)):
64 * csinh(0,0)=(0,0)
65 * csinh(0,inf)=(+-0,NaN)
66 * csinh(0,NaN)=(+-0,NaN)
67 * csinh(x,inf) = (NaN,NaN) for finite positive x
68 * csinh(x,NaN) = (NaN,NaN) for finite non-zero x
69 * csinh(inf,0) = (inf, 0)
70 * csinh(inf,y) = (inf*cos(y),inf*sin(y)) for positive finite y
71 * csinh(inf,inf) = (+-inf,NaN)
72 * csinh(inf,NaN) = (+-inf,NaN)
73 * csinh(NaN,0) = (NaN,0)
74 * csinh(NaN,y) = (NaN,NaN) for non-zero y
75 * csinh(NaN,NaN) = (NaN,NaN)
76 */
77
78 #include "libm.h" /* cosh/exp/fabs/scalbn/sinh/sincos/__k_cexp */
79 #include "complex_wrapper.h"
80
81 dcomplex
82 csinh(dcomplex z)
83 {
84 double t, x, y, S, C;
85 int hx, ix, lx, hy, iy, ly, n;
86 dcomplex ans;
87
88 x = D_RE(z);
89 y = D_IM(z);
90 hx = HI_WORD(x);
91 lx = LO_WORD(x);
92 ix = hx & 0x7fffffff;
93 hy = HI_WORD(y);
94 ly = LO_WORD(y);
95 iy = hy & 0x7fffffff;
96 x = fabs(x);
97 y = fabs(y);
98
99 (void) sincos(y, &S, &C);
100
101 if (ix >= 0x403c0000) { /* |x| > 28 = prec/2 (14,28,34,60) */
102 if (ix >= 0x40862E42) { /* |x| > 709.78... ~ log(2**1024) */
103 if (ix >= 0x7ff00000) { /* |x| is inf or NaN */
104 if ((iy | ly) == 0) {
105 D_RE(ans) = x;
106 D_IM(ans) = y;
107 } else if (iy >= 0x7ff00000) {
108 D_RE(ans) = x;
109 D_IM(ans) = x - y;
110 } else {
111 D_RE(ans) = C * x;
112 D_IM(ans) = S * x;
113 }
114 } else {
115 /* return exp(x)=t*2**n */
116 t = __k_cexp(x, &n);
117 D_RE(ans) = scalbn(C * t, n - 1);
118 D_IM(ans) = scalbn(S * t, n - 1);
119 }
120 } else {
121 t = exp(x) * 0.5;
122 D_RE(ans) = C * t;
123 D_IM(ans) = S * t;
124 }
125 } else {
126 if ((ix | lx) == 0) { /* x = 0, return (0,S) */
127 D_RE(ans) = 0.0;
128 D_IM(ans) = S;
129 } else {
130 D_RE(ans) = C * sinh(x);
131 D_IM(ans) = S * cosh(x);
132 }
133 }
134
135 if (hx < 0)
136 D_RE(ans) = -D_RE(ans);
137
138 if (hy < 0)
139 D_IM(ans) = -D_IM(ans);
140
141 return (ans);
142 }
|