Print this page
5261 libm should stop using synonyms.h
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/LD/sincospil.c
+++ new/usr/src/lib/libm/common/LD/sincospil.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 sincospil = __sincospil
31 -
32 30 /*
33 31 * void sincospil(long double x, long double *s, long double *c)
34 32 * *s = sinl(pi*x); *c = cosl(pi*x);
35 33 *
36 34 * Algorithm, 10/17/2002, K.C. Ng
37 35 * ------------------------------
38 36 * Let y = |4x|, z = floor(y), and n = (int)(z mod 8.0) (displayed in binary).
39 37 * 1. If y == z, then x is a multiple of pi/4. Return the following values:
40 38 * ---------------------------------------------------
41 39 * n x mod 2 sin(x*pi) cos(x*pi) tan(x*pi)
42 40 * ---------------------------------------------------
43 41 * 000 0.00 +0 ___ +1 ___ +0
44 42 * 001 0.25 +\/0.5 +\/0.5 +1
45 43 * 010 0.50 +1 ___ +0 ___ +inf
46 44 * 011 0.75 +\/0.5 -\/0.5 -1
47 45 * 100 1.00 -0 ___ -1 ___ +0
48 46 * 101 1.25 -\/0.5 -\/0.5 +1
49 47 * 110 1.50 -1 ___ -0 ___ +inf
50 48 * 111 1.75 -\/0.5 +\/0.5 -1
51 49 * ---------------------------------------------------
52 50 * 2. Otherwise,
53 51 * ---------------------------------------------------
54 52 * n t sin(x*pi) cos(x*pi) tan(x*pi)
55 53 * ---------------------------------------------------
56 54 * 000 (y-z)/4 sinpi(t) cospi(t) tanpi(t)
57 55 * 001 (z+1-y)/4 cospi(t) sinpi(t) 1/tanpi(t)
58 56 * 010 (y-z)/4 cospi(t) -sinpi(t) -1/tanpi(t)
59 57 * 011 (z+1-y)/4 sinpi(t) -cospi(t) -tanpi(t)
60 58 * 100 (y-z)/4 -sinpi(t) -cospi(t) tanpi(t)
61 59 * 101 (z+1-y)/4 -cospi(t) -sinpi(t) 1/tanpi(t)
62 60 * 110 (y-z)/4 -cospi(t) sinpi(t) -1/tanpi(t)
63 61 * 111 (z+1-y)/4 -sinpi(t) cospi(t) -tanpi(t)
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
64 62 * ---------------------------------------------------
65 63 *
66 64 * NOTE. This program compute sinpi/cospi(t<0.25) by __k_sin/cos(pi*t, 0.0).
67 65 * This will return a result with error slightly more than one ulp (but less
68 66 * than 2 ulp). If one wants accurate result, one may break up pi*t in
69 67 * high (tpi_h) and low (tpi_l) parts and call __k_sin/cos(tip_h, tip_lo)
70 68 * instead.
71 69 */
72 70
73 71 #include "libm.h"
74 -#include "libm_synonyms.h"
75 72 #include "longdouble.h"
76 73
77 74 #include <sys/isa_defs.h>
78 75
79 76 #define I(q, m) ((int *) &(q))[m]
80 77 #define U(q, m) ((unsigned *) &(q))[m]
81 78 #if defined(__i386) || defined(__amd64)
82 79 #define LDBL_MOST_SIGNIF_I(ld) ((I(ld, 2) << 16) | (0xffff & (I(ld, 1) >> 15)))
83 80 #define LDBL_LEAST_SIGNIF_U(ld) U(ld, 0)
84 81 #define PREC 64
85 82 #define PRECM1 63
86 83 #define PRECM2 62
87 84 static const long double twoPRECM2 = 9.223372036854775808000000000000000e+18L;
88 85 #else
89 86 #define LDBL_MOST_SIGNIF_I(ld) I(ld, 0)
90 87 #define LDBL_LEAST_SIGNIF_U(ld) U(ld, sizeof(long double) / sizeof(int) - 1)
91 88 #define PREC 113
92 89 #define PRECM1 112
93 90 #define PRECM2 111
94 91 static const long double twoPRECM2 = 5.192296858534827628530496329220096e+33L;
95 92 #endif
96 93
97 94 static const long double
98 95 zero = 0.0L,
99 96 quater = 0.25L,
100 97 one = 1.0L,
101 98 pi = 3.141592653589793238462643383279502884197e+0000L,
102 99 sqrth = 0.707106781186547524400844362104849039284835937688474,
103 100 tiny = 1.0e-100;
104 101
105 102 void
106 103 sincospil(long double x, long double *s, long double *c) {
107 104 long double y, z, t;
108 105 int hx, n, k;
109 106 unsigned lx;
110 107
111 108 hx = LDBL_MOST_SIGNIF_I(x);
112 109 lx = LDBL_LEAST_SIGNIF_U(x);
113 110 k = ((hx & 0x7fff0000) >> 16) - 0x3fff;
114 111 if (k >= PRECM2) { /* |x| >= 2**(Prec-2) */
115 112 if (k >= 16384) {
116 113 *s = *c = x - x;
117 114 }
118 115 else {
119 116 if (k >= PREC) {
120 117 *s = zero;
121 118 *c = one;
122 119 }
123 120 else if (k == PRECM1) {
124 121 if ((lx & 1) == 0) {
125 122 *s = zero;
126 123 *c = one;
127 124 }
128 125 else {
129 126 *s = -zero;
130 127 *c = -one;
131 128 }
132 129 }
133 130 else { /* k = Prec - 2 */
134 131 if ((lx & 1) == 0) {
135 132 *s = zero;
136 133 *c = one;
137 134 }
138 135 else {
139 136 *s = one;
140 137 *c = zero;
141 138 }
142 139 if ((lx & 2) != 0) {
143 140 *s = -*s;
144 141 *c = -*c;
145 142 }
146 143 }
147 144 }
148 145 }
149 146 else if (k < -2) /* |x| < 0.25 */
150 147 *s = __k_sincosl(pi * fabsl(x), zero, c);
151 148 else {
152 149 /* y = |4x|, z = floor(y), and n = (int)(z mod 8.0) */
153 150 y = 4.0L * fabsl(x);
154 151 if (k < PRECM2) {
155 152 z = y + twoPRECM2;
156 153 n = LDBL_LEAST_SIGNIF_U(z) & 7; /* 3 LSb of z */
157 154 t = z - twoPRECM2;
158 155 k = 0;
159 156 if (t == y)
160 157 k = 1;
161 158 else if (t > y) {
162 159 n -= 1;
163 160 t = quater + (y - t) * quater;
164 161 }
165 162 else
166 163 t = (y - t) * quater;
167 164 }
168 165 else { /* k = Prec-3 */
169 166 n = LDBL_LEAST_SIGNIF_U(y) & 7; /* 3 LSb of z */
170 167 k = 1;
171 168 }
172 169 if (k) { /* x = N/4 */
173 170 if ((n & 1) != 0)
174 171 *s = *c = sqrth + tiny;
175 172 else
176 173 if ((n & 2) == 0) {
177 174 *s = zero;
178 175 *c = one;
179 176 }
180 177 else {
181 178 *s = one;
182 179 *c = zero;
183 180 }
184 181 if ((n & 4) != 0)
185 182 *s = -*s;
186 183 if (((n + 1) & 4) != 0)
187 184 *c = -*c;
188 185 }
189 186 else {
190 187 if ((n & 1) != 0)
191 188 t = quater - t;
192 189 if (((n + (n & 1)) & 2) == 0)
193 190 *s = __k_sincosl(pi * t, zero, c);
194 191 else
195 192 *c = __k_sincosl(pi * t, zero, s);
196 193 if ((n & 4) != 0)
197 194 *s = -*s;
198 195 if (((n + 2) & 4) != 0)
199 196 *c = -*c;
200 197 }
201 198 }
202 199 if (hx < 0)
203 200 *s = -*s;
204 201 }
205 202 #undef U
206 203 #undef LDBL_LEAST_SIGNIF_U
207 204 #undef I
208 205 #undef LDBL_MOST_SIGNIF_I
↓ open down ↓ |
124 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX