Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/LD/__cosl.c
+++ new/usr/src/lib/libm/common/LD/__cosl.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 /* INDENT OFF */
31 31 /*
32 32 * __k_cosl( long double x; long double y )
33 33 * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164
34 34 * Input x is assumed to be bounded by ~pi/4 in magnitude.
35 35 * Input y is the tail of x.
36 36 *
37 37 * Table look up algorithm
38 38 * 1. by cos(-x) = cos(x), we may replace x by |x|
39 39 * 2. if x < 25/128 = [0x3ffc4000, 0] = 0.15625 , then
40 40 * if x < 2^-57 (hx < 0x3fc60000 0), return 1.0 with inexact if x!= 0
41 41 * z = x*x;
42 42 * if x <= 1/128 = 2**-7 = 0.0078125
43 43 * cos(x)=1.0+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))))
44 44 * else
45 45 * cos(x)=1.0+z*(q1+ ... z*q8)
46 46 * 3. else
47 47 * ht = (hx + 0x400)&0x7ffff800 (round x to a break point t)
48 48 * lt = 0
49 49 * i = (hy-0x3ffc4000)>>11; (i<=64)
50 50 * x' = (x - t)+y (|x'| ~<= 2^-7
51 51 * By
52 52 * cos(t+x')
53 53 * = cos(t)cos(x')-sin(t)sin(x')
54 54 * = cos(t)(1+z*(qq1+z*qq2))-[sin(t)]*x*(1+z*(pp1+z*pp2))
55 55 * = cos(t) + [cos(t)]*(z*(qq1+z*qq2))-
56 56 * [sin(t)]*x*(1+z*(pp1+z*pp2))
57 57 *
58 58 * Thus,
59 59 * let a= _TBL_cos_hi[i], b = _TBL_cos_lo[i], c= _TBL_sin_hi[i],
60 60 * x = (x-t)+y
61 61 * z = x*x;
62 62 * cos(t+x) = a+(b+ (-c*x*(1+z*(pp1+z*pp2))+a*(z*(qq1+z*qq2)))
63 63 */
64 64
65 65 #include "libm.h"
66 66
67 67 #include <sys/isa_defs.h>
68 68
69 69 extern const long double _TBL_cosl_hi[], _TBL_cosl_lo[], _TBL_sinl_hi[];
70 70 static const long double
71 71 one = 1.0,
72 72 /*
73 73 * |sin(x) - (x+pp1*x^3+...+ pp5*x^11 )| <= 2^-122.32 for |x|<1/64
74 74 */
75 75 pp1 = -1.666666666666666666666666666586782940810e-0001L,
76 76 pp2 = 8.333333333333333333333003723660929317540e-0003L,
77 77 pp3 = -1.984126984126984076045903483778337804470e-0004L,
78 78 pp4 = 2.755731922361906641319723106210900949413e-0006L,
79 79 pp5 = -2.505198398570947019093998469135012057673e-0008L,
80 80 /*
81 81 *
82 82 * |cos(x) - (1+q1*x^2+...+q8*x^16)| <= 2^-117.11 for |x|<= 0.15625
83 83 */
84 84 q1 = -4.999999999999999999999999999999756416975e-0001L,
85 85 q2 = 4.166666666666666666666666664006066577258e-0002L,
86 86 q3 = -1.388888888888888888888877700363937169637e-0003L,
87 87 q4 = 2.480158730158730158494468463031814083559e-0005L,
88 88 q5 = -2.755731922398586276322819250356005542871e-0007L,
89 89 q6 = 2.087675698767424261441959760729854017855e-0009L,
90 90 q7 = -1.147074481239662089072452129010790774761e-0011L,
91 91 q8 = 4.777761647399651599730663422263531034782e-0014L,
92 92 /*
93 93 *
94 94 * |cos(x) - (1+qq1*x^2+...+ qq5*x^10)| <= 2^-123.84 for |x|<=1/128
95 95 */
96 96 qq1 = -4.999999999999999999999999999999378373641e-0001L,
97 97 qq2 = 4.166666666666666666666665478399327703130e-0002L,
98 98 qq3 = -1.388888888888888888058211230618051613494e-0003L,
↓ open down ↓ |
98 lines elided |
↑ open up ↑ |
99 99 qq4 = 2.480158730156105377771585658905303111866e-0005L,
100 100 qq5 = -2.755728099762526325736488376695157008736e-0007L;
101 101 /* INDENT ON */
102 102 long double
103 103 __k_cosl(long double x, long double y) {
104 104 long double a, t, z, w;
105 105 int *pt = (int *) &t, *px = (int *) &x;
106 106 int i, j, hx, ix;
107 107
108 108 t = 1.0;
109 -#if defined(_BIG_ENDIAN)
110 - hx = px[0];
111 -#else
109 +#if defined(__i386) || defined(__amd64)
112 110 XTOI(px, hx);
111 +#else
112 + hx = px[0];
113 113 #endif
114 114 ix = hx & 0x7fffffff;
115 115 if (ix < 0x3ffc4000) {
116 116 if (ix < 0x3fc60000)
117 117 if ((i = (int) x) == 0)
118 118 return (one); /* generate inexact */
119 119 z = x * x;
120 120
121 121 if (ix < 0x3ff80000) /* 0.0078125 */
122 122 return (one + z * (qq1 + z * (qq2 + z * (qq3 + z *
123 123 (qq4 + z * qq5)))));
124 124 else
125 125 return (one + z * (q1 + z * (q2 + z * (q3 + z * (q4 +
126 126 z * (q5 + z * (q6 + z * (q7 + z * q8))))))));
127 127 }
128 128 j = (ix + 0x400) & 0x7ffff800;
129 129 i = (j - 0x3ffc4000) >> 11;
130 -#if defined(_BIG_ENDIAN)
131 - pt[0] = j;
132 -#else
130 +#if defined(__i386) || defined(__amd64)
133 131 ITOX(j, pt);
132 +#else
133 + pt[0] = j;
134 134 #endif
135 135 if (hx > 0)
136 136 x = y - (t - x);
137 137 else
138 138 x = (-y) - (t + x);
139 139 a = _TBL_cosl_hi[i];
140 140 z = x * x;
141 141 t = z * (qq1 + z * (qq2 + z * (qq3 + z * (qq4 + z * qq5))));
142 142 w = x * (one + z * (pp1 + z * (pp2 + z * (pp3 + z * (pp4 + z *
143 143 pp5)))));
144 144 t = _TBL_cosl_lo[i] - (_TBL_sinl_hi[i] * w - a * t);
145 145 return (a + t);
146 146 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX