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