Print this page
5261 libm should stop using synonyms.h
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/Q/sincospil.c
+++ new/usr/src/lib/libm/common/Q/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)
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 72 #include "longdouble.h"
75 73
76 74 #define I(q, m) ((int *) &(q))[m]
77 75 #define U(q, m) ((unsigned *) &(q))[m]
78 76 #if defined(__LITTLE_ENDIAN) || defined(__x86)
79 77 #define LDBL_MOST_SIGNIF_I(ld) ((I(ld, 2) << 16) | (0xffff & (I(ld, 1) >> 15)))
80 78 #define LDBL_LEAST_SIGNIF_U(ld) U(ld, 0)
81 79 #define PREC 64
82 80 #define PRECM1 63
83 81 #define PRECM2 62
84 82 static const long double twoPRECM2 = 9.223372036854775808000000000000000e+18L;
85 83 #else
86 84 #define LDBL_MOST_SIGNIF_I(ld) I(ld, 0)
87 85 #define LDBL_LEAST_SIGNIF_U(ld) U(ld, sizeof (long double) / sizeof (int) - 1)
88 86 #define PREC 113
89 87 #define PRECM1 112
90 88 #define PRECM2 111
91 89 static const long double twoPRECM2 = 5.192296858534827628530496329220096e+33L;
92 90 #endif
93 91
94 92 static const long double
95 93 zero = 0.0L,
96 94 quater = 0.25L,
97 95 one = 1.0L,
98 96 pi = 3.141592653589793238462643383279502884197e+0000L,
99 97 sqrth = 0.707106781186547524400844362104849039284835937688474,
100 98 tiny = 1.0e-100;
101 99
102 100 void
103 101 sincospil(long double x, long double *s, long double *c) {
104 102 long double y, z, t;
105 103 int hx, n, k;
106 104 unsigned lx;
107 105
108 106 hx = LDBL_MOST_SIGNIF_I(x);
109 107 lx = LDBL_LEAST_SIGNIF_U(x);
110 108 k = ((hx & 0x7fff0000) >> 16) - 0x3fff;
111 109 if (k >= PRECM2) { /* |x| >= 2**(Prec-2) */
112 110 if (k >= 16384) {
113 111 *s = *c = x - x;
114 112 } else {
115 113 if (k >= PREC) {
116 114 *s = zero;
117 115 *c = one;
118 116 } else if (k == PRECM1) {
119 117 if ((lx & 1) == 0) {
120 118 *s = zero;
121 119 *c = one;
122 120 } else {
123 121 *s = -zero;
124 122 *c = -one;
125 123 }
126 124 } else { /* k = Prec - 2 */
127 125 if ((lx & 1) == 0) {
128 126 *s = zero;
129 127 *c = one;
130 128 } else {
131 129 *s = one;
132 130 *c = zero;
133 131 }
134 132 if ((lx & 2) != 0) {
135 133 *s = -*s;
136 134 *c = -*c;
137 135 }
138 136 }
139 137 }
140 138 } else if (k < -2) /* |x| < 0.25 */
141 139 *s = __k_sincosl(pi * fabsl(x), zero, c);
142 140 else {
143 141 /* y = |4x|, z = floor(y), and n = (int)(z mod 8.0) */
144 142 y = 4.0L * fabsl(x);
145 143 if (k < PRECM2) {
146 144 z = y + twoPRECM2;
147 145 n = LDBL_LEAST_SIGNIF_U(z) & 7; /* 3 LSb of z */
148 146 t = z - twoPRECM2;
149 147 k = 0;
150 148 if (t == y)
151 149 k = 1;
152 150 else if (t > y) {
153 151 n -= 1;
154 152 t = quater + (y - t) * quater;
155 153 } else
156 154 t = (y - t) * quater;
157 155 } else { /* k = Prec-3 */
158 156 n = LDBL_LEAST_SIGNIF_U(y) & 7; /* 3 LSb of z */
159 157 k = 1;
160 158 }
161 159 if (k) { /* x = N/4 */
162 160 if ((n & 1) != 0)
163 161 *s = *c = sqrth + tiny;
164 162 else
165 163 if ((n & 2) == 0) {
166 164 *s = zero;
167 165 *c = one;
168 166 } else {
169 167 *s = one;
170 168 *c = zero;
171 169 }
172 170 if ((n & 4) != 0)
173 171 *s = -*s;
174 172 if (((n + 1) & 4) != 0)
175 173 *c = -*c;
176 174 } else {
177 175 if ((n & 1) != 0)
178 176 t = quater - t;
179 177 if (((n + (n & 1)) & 2) == 0)
180 178 *s = __k_sincosl(pi * t, zero, c);
181 179 else
182 180 *c = __k_sincosl(pi * t, zero, s);
183 181 if ((n & 4) != 0)
184 182 *s = -*s;
185 183 if (((n + 2) & 4) != 0)
186 184 *c = -*c;
187 185 }
188 186 }
189 187 if (hx < 0)
190 188 *s = -*s;
191 189 }
192 190 #undef U
193 191 #undef LDBL_LEAST_SIGNIF_U
194 192 #undef I
195 193 #undef LDBL_MOST_SIGNIF_I
↓ open down ↓ |
154 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX