Print this page
5261 libm should stop using synonyms.h
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/C/sincospi.c
+++ new/usr/src/lib/libm/common/C/sincospi.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 sincospi = __sincospi
31 -
32 30 /* INDENT OFF */
33 31 /*
34 32 * void sincospi(double x, double *s, double *c)
35 33 * *s = sin(pi*x); *c = cos(pi*x);
36 34 *
37 35 * Algorithm, 10/17/2002, K.C. Ng
38 36 * ------------------------------
39 37 * Let y = |4x|, z = floor(y), and n = (int)(z mod 8.0) (displayed in binary).
40 38 * 1. If y == z, then x is a multiple of pi/4. Return the following values:
41 39 * ---------------------------------------------------
42 40 * n x mod 2 sin(x*pi) cos(x*pi) tan(x*pi)
43 41 * ---------------------------------------------------
44 42 * 000 0.00 +0 ___ +1 ___ +0
45 43 * 001 0.25 +\/0.5 +\/0.5 +1
46 44 * 010 0.50 +1 ___ +0 ___ +inf
47 45 * 011 0.75 +\/0.5 -\/0.5 -1
48 46 * 100 1.00 -0 ___ -1 ___ +0
49 47 * 101 1.25 -\/0.5 -\/0.5 +1
50 48 * 110 1.50 -1 ___ -0 ___ +inf
51 49 * 111 1.75 -\/0.5 +\/0.5 -1
52 50 * ---------------------------------------------------
53 51 * 2. Otherwise,
54 52 * ---------------------------------------------------
55 53 * n t sin(x*pi) cos(x*pi) tan(x*pi)
56 54 * ---------------------------------------------------
57 55 * 000 (y-z)/4 sinpi(t) cospi(t) tanpi(t)
58 56 * 001 (z+1-y)/4 cospi(t) sinpi(t) 1/tanpi(t)
59 57 * 010 (y-z)/4 cospi(t) -sinpi(t) -1/tanpi(t)
60 58 * 011 (z+1-y)/4 sinpi(t) -cospi(t) -tanpi(t)
61 59 * 100 (y-z)/4 -sinpi(t) -cospi(t) tanpi(t)
62 60 * 101 (z+1-y)/4 -cospi(t) -sinpi(t) 1/tanpi(t)
63 61 * 110 (y-z)/4 -cospi(t) sinpi(t) -1/tanpi(t)
64 62 * 111 (z+1-y)/4 -sinpi(t) cospi(t) -tanpi(t)
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
65 63 * ---------------------------------------------------
66 64 *
67 65 * NOTE. This program compute sinpi/cospi(t<0.25) by __k_sin/cos(pi*t, 0.0).
68 66 * This will return a result with error slightly more than one ulp (but less
69 67 * than 2 ulp). If one wants accurate result, one may break up pi*t in
70 68 * high (tpi_h) and low (tpi_l) parts and call __k_sin/cos(tip_h, tip_lo)
71 69 * instead.
72 70 */
73 71
74 72 #include "libm.h"
75 -#include "libm_synonyms.h"
76 73 #include "libm_protos.h"
77 74 #include "libm_macros.h"
78 75 #include <math.h>
79 76 #if defined(__SUNPRO_C)
80 77 #include <sunmath.h>
81 78 #endif
82 79
83 80 static const double
84 81 pi = 3.14159265358979323846, /* 400921FB,54442D18 */
85 82 sqrth_h = 0.70710678118654757273731092936941422522068023681640625,
86 83 sqrth_l = -4.8336466567264565185935844299127932213411660131004e-17;
87 84 /* INDENT ON */
88 85
89 86 void
90 87 sincospi(double x, double *s, double *c) {
91 88 double y, z, t;
92 89 int n, ix, k;
93 90 int hx = ((int *) &x)[HIWORD];
94 91 unsigned h, lx = ((unsigned *) &x)[LOWORD];
95 92
96 93 ix = hx & ~0x80000000;
97 94 n = (ix >> 20) - 0x3ff;
98 95 if (n >= 51) { /* |x| >= 2**51 */
99 96 if (n >= 1024)
100 97 #if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN)
101 98 *s = *c = ix >= 0x7ff80000 ? x : x - x;
102 99 /* assumes sparc-like QNaN */
103 100 #else
104 101 *s = *c = x - x;
105 102 #endif
106 103 else {
107 104 if (n >= 53) {
108 105 *s = 0.0;
109 106 *c = 1.0;
110 107 }
111 108 else if (n == 52) {
112 109 if ((lx & 1) == 0) {
113 110 *s = 0.0;
114 111 *c = 1.0;
115 112 }
116 113 else {
117 114 *s = -0.0;
118 115 *c = -1.0;
119 116 }
120 117 }
121 118 else { /* n == 51 */
122 119 if ((lx & 1) == 0) {
123 120 *s = 0.0;
124 121 *c = 1.0;
125 122 }
126 123 else {
127 124 *s = 1.0;
128 125 *c = 0.0;
129 126 }
130 127 if ((lx & 2) != 0) {
131 128 *s = -*s;
132 129 *c = -*c;
133 130 }
134 131 }
135 132 }
136 133 }
137 134 else if (n < -2) /* |x| < 0.25 */
138 135 *s = __k_sincos(pi * fabs(x), 0.0, c);
139 136 else {
140 137 /* y = |4x|, z = floor(y), and n = (int)(z mod 8.0) */
141 138 if (ix < 0x41C00000) { /* |x| < 2**29 */
142 139 y = 4.0 * fabs(x);
143 140 n = (int) y; /* exact */
144 141 z = (double) n;
145 142 k = z == y;
146 143 t = (y - z) * 0.25;
147 144 }
148 145 else { /* 2**29 <= |x| < 2**51 */
149 146 y = fabs(x);
150 147 k = 50 - n;
151 148 n = lx >> k;
152 149 h = n << k;
153 150 ((unsigned *) &z)[LOWORD] = h;
154 151 ((int *) &z)[HIWORD] = ix;
155 152 k = h == lx;
156 153 t = y - z;
157 154 }
158 155 if (k) { /* x = N/4 */
159 156 if ((n & 1) != 0)
160 157 *s = *c = sqrth_h + sqrth_l;
161 158 else
162 159 if ((n & 2) == 0) {
163 160 *s = 0.0;
164 161 *c = 1.0;
165 162 }
166 163 else {
167 164 *s = 1.0;
168 165 *c = 0.0;
169 166 }
170 167 y = (n & 2) == 0 ? 0.0 : 1.0;
171 168 if ((n & 4) != 0)
172 169 *s = -*s;
173 170 if (((n + 1) & 4) != 0)
174 171 *c = -*c;
175 172 }
176 173 else {
177 174 if ((n & 1) != 0)
178 175 t = 0.25 - t;
179 176 if (((n + (n & 1)) & 2) == 0)
180 177 *s = __k_sincos(pi * t, 0.0, c);
181 178 else
182 179 *c = __k_sincos(pi * t, 0.0, s);
183 180 if ((n & 4) != 0)
184 181 *s = -*s;
185 182 if (((n + 2) & 4) != 0)
186 183 *c = -*c;
187 184 }
188 185 }
189 186 if (hx < 0)
190 187 *s = -*s;
191 188 }
↓ open down ↓ |
106 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX