Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/R/tanf.c
+++ new/usr/src/lib/libm/common/R/tanf.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
20 20 */
21 21 /*
22 22 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
23 23 */
24 24 /*
25 25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 26 * Use is subject to license terms.
27 27 */
28 28
29 29 #pragma weak tanf = __tanf
30 30
31 31 #include "libm.h"
32 32
33 33 extern const int _TBL_ipio2_inf[];
34 34 extern int __rem_pio2m(double *, double *, int, int, int, const int *);
35 35 #if defined(__i386) && !defined(__amd64)
36 36 extern int __swapRP(int);
37 37 #endif
38 38
39 39 static const double C[] = {
40 40 1.0,
41 41 4.46066928428959230679140546271810308098793029785e-0003,
42 42 4.92165316309189027066395283327437937259674072266e+0000,
43 43 -7.11410648161473480044492134766187518835067749023e-0001,
44 44 4.08549808374053391446523164631798863410949707031e+0000,
45 45 2.50411070398050927821032018982805311679840087891e+0000,
46 46 1.11492064560251158411574579076841473579406738281e+0001,
47 47 -1.50565540968422650891511693771462887525558471680e+0000,
48 48 -1.81484378878349295050043110677506774663925170898e+0000,
49 49 3.333335997532835641297409611782510896641e-0001,
50 50 2.999997598248363761541668282006867229939e+00,
51 51 0.636619772367581343075535, /* 2^ -1 * 1.45F306DC9C883 */
52 52 0.5,
53 53 1.570796326734125614166, /* 2^ 0 * 1.921FB54400000 */
54 54 6.077100506506192601475e-11, /* 2^-34 * 1.0B4611A626331 */
55 55 };
56 56
57 57 #define one C[0]
58 58 #define P0 C[1]
59 59 #define P1 C[2]
60 60 #define P2 C[3]
61 61 #define P3 C[4]
62 62 #define P4 C[5]
63 63 #define P5 C[6]
64 64 #define P6 C[7]
65 65 #define P7 C[8]
66 66 #define T0 C[9]
67 67 #define T1 C[10]
68 68 #define invpio2 C[11]
↓ open down ↓ |
68 lines elided |
↑ open up ↑ |
69 69 #define half C[12]
70 70 #define pio2_1 C[13]
71 71 #define pio2_t C[14]
72 72
73 73 float
74 74 tanf(float x)
75 75 {
76 76 double y, z, w;
77 77 float f;
78 78 int n, ix, hx, hy;
79 + volatile int i;
79 80
80 81 hx = *((int *)&x);
81 82 ix = hx & 0x7fffffff;
82 83
83 84 y = (double)x;
84 85
85 86 if (ix <= 0x4016cbe4) { /* |x| < 3*pi/4 */
86 87 if (ix <= 0x3f490fdb) { /* |x| < pi/4 */
87 88 if (ix < 0x3c000000) { /* |x| < 2**-7 */
88 89 if (ix <= 0x39800000) { /* |x| < 2**-12 */
89 - volatile int i = (int)y;
90 + i = (int)y;
90 91 #ifdef lint
91 92 i = i;
92 93 #endif
93 94 return (x);
94 95 }
95 96 return ((float)((y * T0) * (T1 + y * y)));
96 97 }
97 98 z = y * y;
98 99 return ((float)(((P0 * y) * (P1 + z * (P2 + z)) *
99 100 (P3 + z * (P4 + z))) *
100 101 (P5 + z * (P6 + z * (P7 + z)))));
101 102 }
102 103 if (hx > 0)
103 104 y = (y - pio2_1) - pio2_t;
104 105 else
105 106 y = (y + pio2_1) + pio2_t;
106 107 hy = ((int *)&y)[HIWORD] & ~0x80000000;
107 108 if (hy < 0x3f800000) { /* |y| < 2**-7 */
108 109 z = (y * T0) * (T1 + y * y);
109 110 return ((float)(-one / z));
110 111 }
111 112 z = y * y;
112 113 w = ((P0 * y) * (P1 + z * (P2 + z)) * (P3 + z * (P4 + z))) *
113 114 (P5 + z * (P6 + z * (P7 + z)));
114 115 return ((float)(-one / w));
115 116 }
116 117
117 118 if (ix <= 0x49c90fdb) { /* |x| < 2^19*pi */
118 119 #if defined(__i386) && !defined(__amd64)
119 120 int rp;
120 121
121 122 rp = __swapRP(fp_extended);
122 123 #endif
123 124 w = y * invpio2;
124 125 if (hx < 0)
125 126 n = (int)(w - half);
126 127 else
127 128 n = (int)(w + half);
128 129 y = (y - n * pio2_1) - n * pio2_t;
129 130 #if defined(__i386) && !defined(__amd64)
130 131 if (rp != fp_extended)
131 132 (void) __swapRP(rp);
132 133 #endif
133 134 } else {
134 135 if (ix >= 0x7f800000)
135 136 return (x / x); /* sin(Inf or NaN) is NaN */
136 137 hy = ((int *)&y)[HIWORD];
137 138 n = ((hy >> 20) & 0x7ff) - 1046;
138 139 ((int *)&w)[HIWORD] = (hy & 0xfffff) | 0x41600000;
139 140 ((int *)&w)[LOWORD] = ((int *)&y)[LOWORD];
140 141 n = __rem_pio2m(&w, &y, n, 1, 0, _TBL_ipio2_inf);
141 142 if (hy < 0) {
142 143 y = -y;
143 144 n = -n;
144 145 }
145 146 }
146 147
147 148 hy = ((int *)&y)[HIWORD] & ~0x80000000;
148 149 if (hy < 0x3f800000) { /* |y| < 2**-7 */
149 150 z = (y * T0) * (T1 + y * y);
150 151 f = ((n & 1) == 0)? (float)z : (float)(-one / z);
151 152 return (f);
152 153 }
153 154 z = y * y;
154 155 w = ((P0 * y) * (P1 + z * (P2 + z)) * (P3 + z * (P4 + z))) *
155 156 (P5 + z * (P6 + z * (P7 + z)));
156 157 f = ((n & 1) == 0)? (float)w : (float)(-one / w);
157 158 return (f);
158 159 }
↓ open down ↓ |
59 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX