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