Print this page
11210 libm should be cstyle(1ONBLD) clean
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/complex/ctanh.c
+++ new/usr/src/lib/libm/common/complex/ctanh.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 +
25 26 /*
26 27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 28 * Use is subject to license terms.
28 29 */
29 30
30 31 #pragma weak __ctanh = ctanh
31 32
32 -/* INDENT OFF */
33 +
33 34 /*
34 35 * dcomplex ctanh(dcomplex z);
35 36 *
36 37 * tanh x + i tan y sinh 2x + i sin 2y
37 38 * ctanh z = --------------------- = --------------------
38 39 * 1 + i tanh(x)tan(y) cosh 2x + cos 2y
39 40 *
40 41 * For |x| >= prec/2 (14,28,34,60 for single, double, double extended, quad),
41 42 * we use
42 43 *
43 44 * 1 2x 2 sin 2y
44 45 * cosh 2x = sinh 2x = --- e and hence ctanh z = 1 + i -----------;
45 46 * 2 2x
46 47 * e
47 48 *
48 49 * otherwise, to avoid cancellation, for |x| < prec/2,
49 50 * 2x 2
50 51 * (e - 1) 2 2
51 52 * cosh 2x + cos 2y = 1 + ------------ + cos y - sin y
52 53 * 2x
53 54 * 2 e
54 55 *
55 56 * 1 2x 2 -2x 2
56 57 * = --- (e - 1) e + 2 cos y
57 58 * 2
58 59 * and
59 60 *
60 61 * [ 2x ]
61 62 * 1 [ 2x e - 1 ]
62 63 * sinh 2x = --- [ e - 1 + --------- ]
63 64 * 2 [ 2x ]
64 65 * [ e ]
65 66 * 2x
66 67 * Implementation notes: let t = expm1(2x) = e - 1, then
67 68 *
68 69 * 1 [ t*t 2 ] 1 [ t ]
69 70 * cosh 2x + cos 2y = --- * [ ----- + 4 cos y ]; sinh 2x = --- * [ t + --- ]
70 71 * 2 [ t+1 ] 2 [ t+1 ]
71 72 *
72 73 * Hence,
73 74 *
74 75 *
75 76 * t*t+2t [4(t+1)(cos y)]*(sin y)
76 77 * ctanh z = --------------------------- + i --------------------------
77 78 * t*t+[4(t+1)(cos y)](cos y) t*t+[4(t+1)(cos y)](cos y)
78 79 *
79 80 * EXCEPTION (conform to ISO/IEC 9899:1999(E)):
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
80 81 * ctanh(0,0)=(0,0)
81 82 * ctanh(x,inf) = (NaN,NaN) for finite x
82 83 * ctanh(x,NaN) = (NaN,NaN) for finite x
83 84 * ctanh(inf,y) = 1+ i*0*sin(2y) for positive-signed finite y
84 85 * ctanh(inf,inf) = (1, +-0)
85 86 * ctanh(inf,NaN) = (1, +-0)
86 87 * ctanh(NaN,0) = (NaN,0)
87 88 * ctanh(NaN,y) = (NaN,NaN) for non-zero y
88 89 * ctanh(NaN,NaN) = (NaN,NaN)
89 90 */
90 -/* INDENT ON */
91 91
92 -#include "libm.h" /* exp/expm1/fabs/sin/tanh/sincos */
92 +#include "libm.h" /* exp/expm1/fabs/sin/tanh/sincos */
93 93 #include "complex_wrapper.h"
94 94
95 95 static const double four = 4.0, two = 2.0, one = 1.0, zero = 0.0;
96 96
97 97 dcomplex
98 -ctanh(dcomplex z) {
98 +ctanh(dcomplex z)
99 +{
99 100 double t, r, v, u, x, y, S, C;
100 101 int hx, ix, lx, hy, iy, ly;
101 102 dcomplex ans;
102 103
103 104 x = D_RE(z);
104 105 y = D_IM(z);
105 106 hx = HI_WORD(x);
106 107 lx = LO_WORD(x);
107 108 ix = hx & 0x7fffffff;
108 109 hy = HI_WORD(y);
109 110 ly = LO_WORD(y);
110 111 iy = hy & 0x7fffffff;
111 112 x = fabs(x);
112 113 y = fabs(y);
113 114
114 115 if ((iy | ly) == 0) { /* ctanh(x,0) = (x,0) for x = 0 or NaN */
115 116 D_RE(ans) = tanh(x);
116 117 D_IM(ans) = zero;
117 - } else if (iy >= 0x7ff00000) { /* y is inf or NaN */
118 - if (ix < 0x7ff00000) /* catanh(finite x,inf/nan) is nan */
118 + } else if (iy >= 0x7ff00000) { /* y is inf or NaN */
119 + if (ix < 0x7ff00000) { /* catanh(finite x,inf/nan) is nan */
119 120 D_RE(ans) = D_IM(ans) = y - y;
120 - else if (((ix - 0x7ff00000) | lx) == 0) { /* x is inf */
121 + } else if (((ix - 0x7ff00000) | lx) == 0) { /* x is inf */
121 122 D_RE(ans) = one;
122 123 D_IM(ans) = zero;
123 124 } else {
124 125 D_RE(ans) = x + y;
125 126 D_IM(ans) = y - y;
126 127 }
127 128 } else if (ix >= 0x403c0000) {
128 129 /*
129 130 * |x| > 28 = prec/2 (14,28,34,60)
130 131 * ctanh z ~ 1 + i (sin2y)/(exp(2x))
131 132 */
132 133 D_RE(ans) = one;
133 - if (iy < 0x7fe00000) /* t = sin(2y) */
134 +
135 + if (iy < 0x7fe00000) { /* t = sin(2y) */
134 136 S = sin(y + y);
135 - else {
137 + } else {
136 138 (void) sincos(y, &S, &C);
137 139 S = (S + S) * C;
138 140 }
139 - if (ix >= 0x7fe00000) { /* |x| > max/2 */
141 +
142 + if (ix >= 0x7fe00000) { /* |x| > max/2 */
140 143 if (ix >= 0x7ff00000) { /* |x| is inf or NaN */
141 144 if (((ix - 0x7ff00000) | lx) != 0)
142 145 D_RE(ans) = D_IM(ans) = x + y;
143 - /* x is NaN */
146 + /* x is NaN */
144 147 else
145 148 D_IM(ans) = zero * S; /* x is inf */
146 - } else
149 + } else {
147 150 D_IM(ans) = S * exp(-x); /* underflow */
148 - } else
151 + }
152 + } else {
149 153 D_IM(ans) = (S + S) * exp(-(x + x));
150 - /* 2 sin 2y / exp(2x) */
154 + }
155 +
156 + /* 2 sin 2y / exp(2x) */
151 157 } else {
152 - /* INDENT OFF */
158 + /* BEGIN CSTYLED */
153 159 /*
154 160 * t*t+2t
155 161 * ctanh z = --------------------------- +
156 162 * t*t+[4(t+1)(cos y)](cos y)
157 163 *
158 164 * [4(t+1)(cos y)]*(sin y)
159 165 * i --------------------------
160 166 * t*t+[4(t+1)(cos y)](cos y)
161 167 */
162 - /* INDENT ON */
168 + /* END CSTYLED */
163 169 (void) sincos(y, &S, &C);
164 170 t = expm1(x + x);
165 171 r = (four * C) * (t + one);
166 172 u = t * t;
167 173 v = one / (u + r * C);
168 174 D_RE(ans) = (u + two * t) * v;
169 175 D_IM(ans) = (r * S) * v;
170 176 }
177 +
171 178 if (hx < 0)
172 179 D_RE(ans) = -D_RE(ans);
180 +
173 181 if (hy < 0)
174 182 D_IM(ans) = -D_IM(ans);
183 +
175 184 return (ans);
176 185 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX