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