Print this page
11210 libm should be cstyle(1ONBLD) clean
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/LD/__sinl.c
+++ new/usr/src/lib/libm/common/LD/__sinl.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 -/* INDENT OFF */
31 +
31 32 /*
32 33 * __k_sinl( long double x; long double y )
33 34 * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.785398164
34 35 * Input x is assumed to be bounded by ~pi/4 in magnitude.
35 36 * Input y is the tail of x.
36 37 *
37 38 * Table look up algorithm
38 39 * 1. by sin(-x) = -sin(x), need only to consider positive x
39 40 * 2. if x < 25/128 = [0x3ffc9000,0,0,0] = 0.1953125 , then
40 41 * if x < 2^-57 (hx < 0x3fc60000,0,0,0), return x (inexact if x != 0)
41 42 * z = x*x;
42 43 * if x <= 1/64 = 2**-6
43 44 * sin(x) = x + (y+(x*z)*(p1 + z*p2))
44 45 * else
45 46 * sin(x) = x + (y+(x*z)*(p1 + z*(p2 + z*(p3 + z*p4))))
46 47 * 3. else
47 48 * ht = (hx + 0x400)&0x7ffff800 (round x to a break point t)
48 49 * lt = 0
49 50 * i = (hy-0x3ffc4000)>>11; (i<=64)
50 - * x' = (x - t)+y (|x'| ~<= 2^-7
51 + * x' = (x - t)+y (|x'| ~<= 2^-7
51 52 * By
52 53 * sin(t+x')
53 54 * = sin(t)cos(x')+cos(t)sin(x')
54 55 * = sin(t)(1+z*(qq1+z*qq2))+[cos(t)]*x*(1+z*(pp1+z*pp2))
55 56 * = sin(t) + [sin(t)]*(z*(qq1+z*qq2))+
56 57 * [cos(t)]*x*(1+z*(pp1+z*pp2))
57 58 *
58 59 * Thus,
59 60 * let a= _TBL_sin_hi[i], b = _TBL_sin_lo[i], c= _TBL_cos_hi[i],
60 61 * x = (x-t)+y
61 62 * z = x*x;
62 63 * sin(t+x) = a+(b+ ((c*x)*(1+z*(pp1+z*pp2))+a*(z*(qq1+z*qq2)))
63 64 */
64 65
65 66 #include "libm.h"
66 67
67 68 #include <sys/isa_defs.h>
68 69
69 70 extern const long double _TBL_sinl_hi[], _TBL_sinl_lo[], _TBL_cosl_hi[];
70 -static const long double
71 -one = 1.0,
71 +static const long double one = 1.0;
72 +
72 73 /*
73 74 * |sin(x) - (x+pp1*x^3+...+ pp5*x^11)| <= 2^-122.32 for |x|<1/64
74 75 */
75 -pp1 = -1.666666666666666666666666666586782940810e-0001L,
76 -pp2 = 8.333333333333333333333003723660929317540e-0003L,
77 -pp3 = -1.984126984126984076045903483778337804470e-0004L,
78 -pp4 = 2.755731922361906641319723106210900949413e-0006L,
79 -pp5 = -2.505198398570947019093998469135012057673e-0008L,
76 +static const long double
77 + pp1 = -1.666666666666666666666666666586782940810e-0001L,
78 + pp2 = 8.333333333333333333333003723660929317540e-0003L,
79 + pp3 = -1.984126984126984076045903483778337804470e-0004L,
80 + pp4 = 2.755731922361906641319723106210900949413e-0006L,
81 + pp5 = -2.505198398570947019093998469135012057673e-0008L;
82 +
80 83 /*
81 84 * |(sin(x) - (x+p1*x^3+...+p8*x^17)|
82 85 * |------------------------------- | <= 2^-116.17 for |x|<0.1953125
83 86 * | x |
84 87 */
85 -p1 = -1.666666666666666666666666666666211262297e-0001L,
86 -p2 = 8.333333333333333333333333301497876908541e-0003L,
87 -p3 = -1.984126984126984126984041302881180621922e-0004L,
88 -p4 = 2.755731922398589064100587351307269621093e-0006L,
89 -p5 = -2.505210838544163129378906953765595393873e-0008L,
90 -p6 = 1.605904383643244375050998243778534074273e-0010L,
91 -p7 = -7.647162722800685516901456114270824622699e-0013L,
92 -p8 = 2.810046428661902961725428841068844462603e-0015L,
88 +static const long double
89 + p1 = -1.666666666666666666666666666666211262297e-0001L,
90 + p2 = 8.333333333333333333333333301497876908541e-0003L,
91 + p3 = -1.984126984126984126984041302881180621922e-0004L,
92 + p4 = 2.755731922398589064100587351307269621093e-0006L,
93 + p5 = -2.505210838544163129378906953765595393873e-0008L,
94 + p6 = 1.605904383643244375050998243778534074273e-0010L,
95 + p7 = -7.647162722800685516901456114270824622699e-0013L,
96 + p8 = 2.810046428661902961725428841068844462603e-0015L;
97 +
93 98 /*
94 99 * 2 10 -123.84
95 100 * |cos(x) - (1+qq1*x +...+ qq5*x )| <= 2 for |x|<=1/128
96 101 */
97 -qq1 = -4.999999999999999999999999999999378373641e-0001L,
98 -qq2 = 4.166666666666666666666665478399327703130e-0002L,
99 -qq3 = -1.388888888888888888058211230618051613494e-0003L,
100 -qq4 = 2.480158730156105377771585658905303111866e-0005L,
101 -qq5 = -2.755728099762526325736488376695157008736e-0007L;
102 -/* INDENT ON */
102 +static const long double
103 + qq1 = -4.999999999999999999999999999999378373641e-0001L,
104 + qq2 = 4.166666666666666666666665478399327703130e-0002L,
105 + qq3 = -1.388888888888888888058211230618051613494e-0003L,
106 + qq4 = 2.480158730156105377771585658905303111866e-0005L,
107 + qq5 = -2.755728099762526325736488376695157008736e-0007L;
108 +
109 +
103 110 long double
104 -__k_sinl(long double x, long double y) {
111 +__k_sinl(long double x, long double y)
112 +{
105 113 long double a, t, z, w;
106 - int *pt = (int *) &t, *px = (int *) &x;
114 + int *pt = (int *)&t, *px = (int *)&x;
107 115 int i, j, hx, ix;
108 116
109 117 t = 1.0L;
110 118 #if defined(__i386) || defined(__amd64)
111 119 XTOI(px, hx);
112 120 #else
113 121 hx = px[0];
114 122 #endif
115 123 ix = hx & 0x7fffffff;
124 +
116 125 if (ix < 0x3ffc9000) {
117 126 if (ix < 0x3fc60000)
118 - if (((int) x) == 0)
119 - return (x); /* generate inexact */
127 + if (((int)x) == 0)
128 + return (x);
129 +
130 + /* generate inexact */
120 131 z = x * x;
121 - t = z * (p1 + z * (p2 + z * (p3 + z * (p4 + z * (p5 + z *
122 - (p6 + z * (p7 + z * p8)))))));
132 + t = z * (p1 + z * (p2 + z * (p3 + z * (p4 + z * (p5 + z * (p6 +
133 + z * (p7 + z * p8)))))));
123 134 t = y + x * t;
124 135 return (x + t);
125 136 }
137 +
126 138 j = (ix + 0x400) & 0x7ffff800;
127 139 i = (j - 0x3ffc4000) >> 11;
128 140 #if defined(__i386) || defined(__amd64)
129 141 ITOX(j, pt);
130 142 #else
131 143 pt[0] = j;
132 144 #endif
145 +
133 146 if (hx > 0)
134 147 x = y - (t - x);
135 148 else
136 149 x = (-y) - (t + x);
150 +
137 151 a = _TBL_sinl_hi[i];
138 152 z = x * x;
139 153 t = z * (qq1 + z * (qq2 + z * (qq3 + z * (qq4 + z * qq5))));
140 - w = x * (one + z * (pp1 + z * (pp2 + z * (pp3 + z * (pp4 + z *
141 - pp5)))));
154 + w = x * (one + z * (pp1 + z * (pp2 + z * (pp3 + z * (pp4 + z * pp5)))));
142 155 t = _TBL_cosl_hi[i] * w + a * t;
143 156 t += _TBL_sinl_lo[i];
157 +
144 158 if (hx < 0)
145 159 return (-a - t);
146 160 else
147 161 return (a + t);
148 162 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX