Print this page
5261 libm should stop using synonyms.h
5298 fabs is 0-sized, confuses dis(1) and others
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Approved by: Gordon Ross <gwr@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/complex/ctanhf.c
+++ new/usr/src/lib/libm/common/complex/ctanhf.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.
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
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
20 20 */
21 21
22 22 /*
23 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 25 /*
26 26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 27 * Use is subject to license terms.
28 28 */
29 29
30 -#pragma weak ctanhf = __ctanhf
30 +#pragma weak __ctanhf = ctanhf
31 31
32 32 #include "libm.h" /* expf/expm1f/fabsf/sincosf/sinf/tanhf */
33 33 #include "complex_wrapper.h"
34 34
35 35 /* INDENT OFF */
36 36 static const float four = 4.0F, two = 2.0F, one = 1.0F, zero = 0.0F;
37 37 /* INDENT ON */
38 38
39 39 fcomplex
40 40 ctanhf(fcomplex z) {
41 41 float r, u, v, t, x, y, S, C;
42 42 int hx, ix, hy, iy;
43 43 fcomplex ans;
44 44
45 45 x = F_RE(z);
46 46 y = F_IM(z);
47 47 hx = THE_WORD(x);
48 48 ix = hx & 0x7fffffff;
49 49 hy = THE_WORD(y);
50 50 iy = hy & 0x7fffffff;
51 51 x = fabsf(x);
52 52 y = fabsf(y);
53 53
54 54 if (iy == 0) { /* ctanh(x,0) = (x,0) for x = 0 or NaN */
55 55 F_RE(ans) = tanhf(x);
56 56 F_IM(ans) = zero;
57 57 } else if (iy >= 0x7f800000) { /* y is inf or NaN */
58 58 if (ix < 0x7f800000) /* catanh(finite x,inf/nan) is nan */
59 59 F_RE(ans) = F_IM(ans) = y - y;
60 60 else if (ix == 0x7f800000) { /* x is inf */
61 61 F_RE(ans) = one;
62 62 F_IM(ans) = zero;
63 63 } else {
64 64 F_RE(ans) = x + y;
65 65 F_IM(ans) = y - y;
66 66 }
67 67 } else if (ix >= 0x41600000) {
68 68 /*
69 69 * |x| > 14 = prec/2 (14,28,34,60)
70 70 * ctanh z ~ 1 + i (sin2y)/(exp(2x))
71 71 */
72 72 F_RE(ans) = one;
73 73 if (iy < 0x7f000000) /* t = sin(2y) */
74 74 S = sinf(y + y);
75 75 else {
76 76 (void) sincosf(y, &S, &C);
77 77 S = (S + S) * C;
78 78 }
79 79 if (ix >= 0x7f000000) { /* |x| > max/2 */
80 80 if (ix >= 0x7f800000) { /* |x| is inf or NaN */
81 81 if (ix > 0x7f800000) /* x is NaN */
82 82 F_RE(ans) = F_IM(ans) = x + y;
83 83 else
84 84 F_IM(ans) = zero * S; /* x is inf */
85 85 } else
86 86 F_IM(ans) = S * expf(-x); /* underflow */
87 87 } else
88 88 F_IM(ans) = (S + S) * expf(-(x + x));
89 89 /* 2 sin 2y / exp(2x) */
90 90 } else {
91 91 /* INDENT OFF */
92 92 /*
93 93 * t*t+2t
94 94 * ctanh z = ---------------------------
95 95 * t*t+[4(t+1)(cos y)](cos y)
96 96 *
97 97 * [4(t+1)(cos y)]*(sin y)
98 98 * i --------------------------
99 99 * t*t+[4(t+1)(cos y)](cos y)
100 100 */
101 101 /* INDENT ON */
102 102 (void) sincosf(y, &S, &C);
103 103 t = expm1f(x + x);
104 104 r = (four * C) * (t + one);
105 105 u = t * t;
106 106 v = one / (u + r * C);
107 107 F_RE(ans) = (u + two * t) * v;
108 108 F_IM(ans) = (r * S) * v;
109 109 }
110 110 if (hx < 0)
111 111 F_RE(ans) = -F_RE(ans);
112 112 if (hy < 0)
113 113 F_IM(ans) = -F_IM(ans);
114 114 return (ans);
115 115 }
↓ open down ↓ |
75 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX