Print this page
5261 libm should stop using synonyms.h
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/Q/expm1l.c
+++ new/usr/src/lib/libm/common/Q/expm1l.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 expm1l = __expm1l
30 +#pragma weak __expm1l = expm1l
31 +
31 32 #if !defined(__sparc)
32 33 #error Unsupported architecture
33 34 #endif
34 35
35 36 /*
36 37 * expm1l(x)
37 38 *
38 39 * Table driven method
39 40 * Written by K.C. Ng, June 1995.
40 41 * Algorithm :
41 42 * 1. expm1(x) = x if x<2**-114
42 43 * 2. if |x| <= 0.0625 = 1/16, use approximation
43 44 * expm1(x) = x + x*P/(2-P)
44 45 * where
45 46 * P = x - z*(P1+z*(P2+z*(P3+z*(P4+z*(P5+z*P6+z*P7))))), z = x*x;
46 47 * (this formula is derived from
47 48 * 2-P+x = R = x*(exp(x)+1)/(exp(x)-1) ~ 2 + x*x/6 - x^4/360 + ...)
48 49 *
49 50 * P1 = 1.66666666666666666666666666666638500528074603030e-0001
50 51 * P2 = -2.77777777777777777777777759668391122822266551158e-0003
51 52 * P3 = 6.61375661375661375657437408890138814721051293054e-0005
52 53 * P4 = -1.65343915343915303310185228411892601606669528828e-0006
53 54 * P5 = 4.17535139755122945763580609663414647067443411178e-0008
54 55 * P6 = -1.05683795988668526689182102605260986731620026832e-0009
55 56 * P7 = 2.67544168821852702827123344217198187229611470514e-0011
56 57 *
57 58 * Accuracy: |R-x*(exp(x)+1)/(exp(x)-1)|<=2**-119.13
58 59 *
59 60 * 3. For 1/16 < |x| < 1.125, choose x(+-i) ~ +-(i+4.5)/64, i=0,..,67
60 61 * since
61 62 * exp(x) = exp(xi+(x-xi))= exp(xi)*exp((x-xi))
62 63 * we have
63 64 * expm1(x) = expm1(xi)+(exp(xi))*(expm1(x-xi))
64 65 * where
65 66 * |s=x-xi| <= 1/128
66 67 * and
67 68 * expm1(s)=2s/(2-R), R= s-s^2*(T1+s^2*(T2+s^2*(T3+s^2*(T4+s^2*T5))))
68 69 *
69 70 * T1 = 1.666666666666666666666666666660876387437e-1L,
70 71 * T2 = -2.777777777777777777777707812093173478756e-3L,
71 72 * T3 = 6.613756613756613482074280932874221202424e-5L,
72 73 * T4 = -1.653439153392139954169609822742235851120e-6L,
73 74 * T5 = 4.175314851769539751387852116610973796053e-8L;
74 75 *
75 76 * 4. For |x| >= 1.125, return exp(x)-1.
76 77 * (see algorithm for exp)
77 78 *
78 79 * Special cases:
79 80 * expm1l(INF) is INF, expm1l(NaN) is NaN;
80 81 * expm1l(-INF)= -1;
81 82 * for finite argument, only expm1l(0)=0 is exact.
82 83 *
83 84 * Accuracy:
84 85 * according to an error analysis, the error is always less than
85 86 * 2 ulp (unit in the last place).
86 87 *
87 88 * Misc. info.
88 89 * For 113 bit long double
89 90 * if x > 1.135652340629414394949193107797076342845e+4
90 91 * then expm1l(x) overflow;
91 92 *
92 93 * Constants:
93 94 * Only decimal values are given. We assume that the compiler will convert
94 95 * from decimal to binary accurately enough to produce the correct
95 96 * hexadecimal values.
96 97 */
97 98
98 99 #include "libm.h"
99 100
100 101 extern const long double _TBL_expl_hi[], _TBL_expl_lo[];
101 102 extern const long double _TBL_expm1lx[], _TBL_expm1l[];
102 103
103 104 static const long double
104 105 zero = +0.0L,
105 106 one = +1.0L,
106 107 two = +2.0L,
107 108 ln2_64 = +1.083042469624914545964425189778400898568e-2L,
108 109 ovflthreshold = +1.135652340629414394949193107797076342845e+4L,
109 110 invln2_32 = +4.616624130844682903551758979206054839765e+1L,
110 111 ln2_32hi = +2.166084939249829091928849858592451515688e-2L,
111 112 ln2_32lo = +5.209643502595475652782654157501186731779e-27L,
112 113 huge = +1.0e4000L,
113 114 tiny = +1.0e-4000L,
114 115 P1 = +1.66666666666666666666666666666638500528074603030e-0001L,
115 116 P2 = -2.77777777777777777777777759668391122822266551158e-0003L,
116 117 P3 = +6.61375661375661375657437408890138814721051293054e-0005L,
117 118 P4 = -1.65343915343915303310185228411892601606669528828e-0006L,
118 119 P5 = +4.17535139755122945763580609663414647067443411178e-0008L,
119 120 P6 = -1.05683795988668526689182102605260986731620026832e-0009L,
120 121 P7 = +2.67544168821852702827123344217198187229611470514e-0011L,
121 122 /* rational approximation coeffs for [-(ln2)/64,(ln2)/64] */
122 123 T1 = +1.666666666666666666666666666660876387437e-1L,
123 124 T2 = -2.777777777777777777777707812093173478756e-3L,
124 125 T3 = +6.613756613756613482074280932874221202424e-5L,
125 126 T4 = -1.653439153392139954169609822742235851120e-6L,
126 127 T5 = +4.175314851769539751387852116610973796053e-8L;
127 128
128 129 long double
129 130 expm1l(long double x) {
130 131 int hx, ix, j, k, m;
131 132 long double t, r, s, w;
132 133
133 134 hx = ((int *) &x)[HIXWORD];
134 135 ix = hx & ~0x80000000;
135 136 if (ix >= 0x7fff0000) {
136 137 if (x != x)
137 138 return (x + x); /* NaN */
138 139 if (x < zero)
139 140 return (-one); /* -inf */
140 141 return (x); /* +inf */
141 142 }
142 143 if (ix < 0x3fff4000) { /* |x| < 1.25 */
143 144 if (ix < 0x3ffb0000) { /* |x| < 0.0625 */
144 145 if (ix < 0x3f8d0000) {
145 146 if ((int) x == 0)
146 147 return (x); /* |x|<2^-114 */
147 148 }
148 149 t = x * x;
149 150 r = (x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t *
150 151 (P5 + t * (P6 + t * P7)))))));
151 152 return (x + (x * r) / (two - r));
152 153 }
153 154 /* compute i = [64*x] */
154 155 m = 0x4009 - (ix >> 16);
155 156 j = ((ix & 0x0000ffff) | 0x10000) >> m; /* j=4,...,67 */
156 157 if (hx < 0)
157 158 j += 82; /* negative */
158 159 s = x - _TBL_expm1lx[j];
159 160 t = s * s;
160 161 r = s - t * (T1 + t * (T2 + t * (T3 + t * (T4 + t * T5))));
161 162 r = (s + s) / (two - r);
162 163 w = _TBL_expm1l[j];
163 164 return (w + (w + one) * r);
164 165 }
165 166 if (hx > 0) {
166 167 if (x > ovflthreshold)
167 168 return (huge * huge);
168 169 k = (int) (invln2_32 * (x + ln2_64));
169 170 } else {
170 171 if (x < -80.0)
171 172 return (tiny - x / x);
172 173 k = (int) (invln2_32 * (x - ln2_64));
173 174 }
174 175 j = k & 0x1f;
175 176 m = k >> 5;
176 177 t = (long double) k;
177 178 x = (x - t * ln2_32hi) - t * ln2_32lo;
178 179 t = x * x;
179 180 r = (x - t * (T1 + t * (T2 + t * (T3 + t * (T4 + t * T5))))) - two;
180 181 x = _TBL_expl_hi[j] - ((_TBL_expl_hi[j] * (x + x)) / r -
181 182 _TBL_expl_lo[j]);
182 183 return (scalbnl(x, m) - one);
183 184 }
↓ open down ↓ |
143 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX