crmf 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -0
  3. data/crmf.gemspec +105 -3
  4. data/ext/crlibm-1.0beta5/AUTHORS +2 -0
  5. data/ext/crlibm-1.0beta5/CMakeLists.txt +154 -0
  6. data/ext/crlibm-1.0beta5/COPYING +340 -0
  7. data/ext/crlibm-1.0beta5/COPYING.LIB +504 -0
  8. data/ext/crlibm-1.0beta5/ChangeLog +125 -0
  9. data/ext/crlibm-1.0beta5/Makefile.am +134 -0
  10. data/ext/crlibm-1.0beta5/NEWS +0 -0
  11. data/ext/crlibm-1.0beta5/README +31 -0
  12. data/ext/crlibm-1.0beta5/README.DEV +23 -0
  13. data/ext/crlibm-1.0beta5/README.md +5 -0
  14. data/ext/crlibm-1.0beta5/TODO +66 -0
  15. data/ext/crlibm-1.0beta5/VERSION +1 -0
  16. data/ext/crlibm-1.0beta5/acos-td.c +1195 -0
  17. data/ext/crlibm-1.0beta5/acos-td.h +629 -0
  18. data/ext/crlibm-1.0beta5/asin-td.c +1297 -0
  19. data/ext/crlibm-1.0beta5/asin-td.h +620 -0
  20. data/ext/crlibm-1.0beta5/asincos.c +4488 -0
  21. data/ext/crlibm-1.0beta5/asincos.h +575 -0
  22. data/ext/crlibm-1.0beta5/atan-itanium.c +846 -0
  23. data/ext/crlibm-1.0beta5/atan-pentium.c +280 -0
  24. data/ext/crlibm-1.0beta5/atan-pentium.h +343 -0
  25. data/ext/crlibm-1.0beta5/atan_accurate.c +341 -0
  26. data/ext/crlibm-1.0beta5/atan_accurate.h +198 -0
  27. data/ext/crlibm-1.0beta5/atan_fast.c +506 -0
  28. data/ext/crlibm-1.0beta5/atan_fast.h +680 -0
  29. data/ext/crlibm-1.0beta5/configure.ac +419 -0
  30. data/ext/crlibm-1.0beta5/crlibm.h +204 -0
  31. data/ext/crlibm-1.0beta5/crlibm.spec +42 -0
  32. data/ext/crlibm-1.0beta5/crlibm_private.c +397 -0
  33. data/ext/crlibm-1.0beta5/crlibm_private.h +1048 -0
  34. data/ext/crlibm-1.0beta5/csh_fast.c +721 -0
  35. data/ext/crlibm-1.0beta5/csh_fast.h +771 -0
  36. data/ext/crlibm-1.0beta5/double-extended.h +496 -0
  37. data/ext/crlibm-1.0beta5/exp-itanium.c +723 -0
  38. data/ext/crlibm-1.0beta5/exp-td-standalone.c +87 -0
  39. data/ext/crlibm-1.0beta5/exp-td.c +1363 -0
  40. data/ext/crlibm-1.0beta5/exp-td.h +685 -0
  41. data/ext/crlibm-1.0beta5/exp_build_coeffs/exp_fast_table.c +125 -0
  42. data/ext/crlibm-1.0beta5/expm1-standalone.c +119 -0
  43. data/ext/crlibm-1.0beta5/expm1.c +2515 -0
  44. data/ext/crlibm-1.0beta5/expm1.h +715 -0
  45. data/ext/crlibm-1.0beta5/interval.h +238 -0
  46. data/ext/crlibm-1.0beta5/log-de.c +480 -0
  47. data/ext/crlibm-1.0beta5/log-de.h +747 -0
  48. data/ext/crlibm-1.0beta5/log-de2.c +280 -0
  49. data/ext/crlibm-1.0beta5/log-de2.h +2352 -0
  50. data/ext/crlibm-1.0beta5/log-td.c +1158 -0
  51. data/ext/crlibm-1.0beta5/log-td.h +819 -0
  52. data/ext/crlibm-1.0beta5/log.c +2244 -0
  53. data/ext/crlibm-1.0beta5/log.h +1592 -0
  54. data/ext/crlibm-1.0beta5/log10-td.c +906 -0
  55. data/ext/crlibm-1.0beta5/log10-td.h +823 -0
  56. data/ext/crlibm-1.0beta5/log1p.c +1295 -0
  57. data/ext/crlibm-1.0beta5/log2-td.c +1521 -0
  58. data/ext/crlibm-1.0beta5/log2-td.h +821 -0
  59. data/ext/crlibm-1.0beta5/log2_accurate.c +330 -0
  60. data/ext/crlibm-1.0beta5/log2_accurate.h +261 -0
  61. data/ext/crlibm-1.0beta5/log_accurate.c +133 -0
  62. data/ext/crlibm-1.0beta5/log_accurate.h +261 -0
  63. data/ext/crlibm-1.0beta5/log_fast.c +360 -0
  64. data/ext/crlibm-1.0beta5/log_fast.h +440 -0
  65. data/ext/crlibm-1.0beta5/pow.c +1396 -0
  66. data/ext/crlibm-1.0beta5/pow.h +3101 -0
  67. data/ext/crlibm-1.0beta5/prepare +20 -0
  68. data/ext/crlibm-1.0beta5/rem_pio2_accurate.c +219 -0
  69. data/ext/crlibm-1.0beta5/rem_pio2_accurate.h +53 -0
  70. data/ext/crlibm-1.0beta5/scs_lib/AUTHORS +3 -0
  71. data/ext/crlibm-1.0beta5/scs_lib/COPYING +504 -0
  72. data/ext/crlibm-1.0beta5/scs_lib/ChangeLog +16 -0
  73. data/ext/crlibm-1.0beta5/scs_lib/Doxyfile.dev +939 -0
  74. data/ext/crlibm-1.0beta5/scs_lib/Doxyfile.user +939 -0
  75. data/ext/crlibm-1.0beta5/scs_lib/INSTALL +215 -0
  76. data/ext/crlibm-1.0beta5/scs_lib/Makefile.am +17 -0
  77. data/ext/crlibm-1.0beta5/scs_lib/NEWS +0 -0
  78. data/ext/crlibm-1.0beta5/scs_lib/README +9 -0
  79. data/ext/crlibm-1.0beta5/scs_lib/README.DEV +38 -0
  80. data/ext/crlibm-1.0beta5/scs_lib/TODO +4 -0
  81. data/ext/crlibm-1.0beta5/scs_lib/VERSION +1 -0
  82. data/ext/crlibm-1.0beta5/scs_lib/addition_scs.c +623 -0
  83. data/ext/crlibm-1.0beta5/scs_lib/division_scs.c +110 -0
  84. data/ext/crlibm-1.0beta5/scs_lib/double2scs.c +174 -0
  85. data/ext/crlibm-1.0beta5/scs_lib/main.dox +104 -0
  86. data/ext/crlibm-1.0beta5/scs_lib/multiplication_scs.c +339 -0
  87. data/ext/crlibm-1.0beta5/scs_lib/poly_fct.c +112 -0
  88. data/ext/crlibm-1.0beta5/scs_lib/print_scs.c +73 -0
  89. data/ext/crlibm-1.0beta5/scs_lib/rand_scs.c +63 -0
  90. data/ext/crlibm-1.0beta5/scs_lib/scs.h +353 -0
  91. data/ext/crlibm-1.0beta5/scs_lib/scs2double.c +411 -0
  92. data/ext/crlibm-1.0beta5/scs_lib/scs2mpf.c +58 -0
  93. data/ext/crlibm-1.0beta5/scs_lib/scs2mpfr.c +61 -0
  94. data/ext/crlibm-1.0beta5/scs_lib/scs_private.c +23 -0
  95. data/ext/crlibm-1.0beta5/scs_lib/scs_private.h +133 -0
  96. data/ext/crlibm-1.0beta5/scs_lib/wrapper_scs.h +486 -0
  97. data/ext/crlibm-1.0beta5/scs_lib/zero_scs.c +52 -0
  98. data/ext/crlibm-1.0beta5/trigo_accurate.c +501 -0
  99. data/ext/crlibm-1.0beta5/trigo_accurate.h +331 -0
  100. data/ext/crlibm-1.0beta5/trigo_fast.c +1243 -0
  101. data/ext/crlibm-1.0beta5/trigo_fast.h +639 -0
  102. data/ext/crlibm-1.0beta5/trigpi.c +1169 -0
  103. data/ext/crlibm-1.0beta5/trigpi.h +556 -0
  104. data/ext/crlibm-1.0beta5/triple-double.c +57 -0
  105. data/ext/crlibm-1.0beta5/triple-double.h +1380 -0
  106. data/ext/crmf/crmf.c +117 -20
  107. data/ext/crmf/extconf.rb +12 -8
  108. data/lib/crmf/version.rb +1 -1
  109. data/tests/perf.rb +100 -219
  110. metadata +108 -10
  111. data/ext/crlibm-1.0beta4.tar.gz +0 -0
@@ -0,0 +1,330 @@
1
+ /*
2
+ * Correctly rounded base 2 logarithm
3
+ *
4
+ * Author : David Defour
5
+ *
6
+ * This file is part of the crlibm library developed by the Arenaire
7
+ * project at Ecole Normale Superieure de Lyon
8
+ *
9
+ * This program is free software; you can redistribute it and/or modify
10
+ * it under the terms of the GNU Lesser General Public License as published by
11
+ * the Free Software Foundation; either version 2 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public License
20
+ * along with this program; if not, write to the Free Software
21
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
+ */
23
+
24
+ #include "log2_accurate.h"
25
+
26
+ /*
27
+ * 1) First reduction: exponent extraction
28
+ * E
29
+ * x = 2^ .(1+f) with 0 <= f < 1
30
+ *
31
+ * log2(x) = E + log2(1+f) where:
32
+ * - log2(1+f) need to be evalute
33
+ *
34
+ *
35
+ * 2) Avoiding accuracy problem when E=-1 by testing
36
+ *
37
+ * if (1+f >= sqrt(2)) then
38
+ * 1+f = (1+f)/2; E = E+1;
39
+ * and,
40
+ * log2(x) = (E+1) + log2((1+f)/2)
41
+ *
42
+ * so now: sqrt(2)/2 <= (1+f) < sqrt(2)
43
+ *
44
+ *
45
+ * 3) Second reduction: tabular reduction
46
+ * -4
47
+ * wi = 1 + i. 2^
48
+ * 1
49
+ * log2(1+f) = log2(wi) + log2 ( 1 + --- . (1 + f - wi) )
50
+ * wi
51
+ *
52
+ * then |(1+f-wi)/wi| <= 2^-5 if we use rounded to nearest.
53
+ *
54
+ * 4) Computation:
55
+ * a) Table lookup of:
56
+ * - ti = log2(wi)
57
+ * - inv_wi = 1/(wi)
58
+ * b) Polynomial evaluation of:
59
+ * - P(R) ~ log2(1 + R), where R = (1+f-wi) * inv_wi
60
+ *
61
+ * -5
62
+ * with |R| < 2^
63
+ *
64
+ *
65
+ * 5) Reconstruction:
66
+ * log2(x) = E + t_i + P(R)
67
+ *
68
+ *
69
+ * Note 1:
70
+ * To guarantee log2(2^n)=n, where 2^n is normal, the rounding
71
+ * mode must set to Round-to-Nearest.
72
+ *
73
+ * Special cases:
74
+ * log2(x) is NaN with signal if x < 0;
75
+ * log2(+INF) is +INF with no signal; log2(0) is -INF with signal;
76
+ * log2(NaN) is that NaN with no signal;
77
+ * log2(2^N) = N
78
+ *
79
+ */
80
+ #define SQRT_2 1.4142135623730950489e0
81
+
82
+
83
+ /*************************************************************
84
+ *************************************************************
85
+ * ROUNDED TO NEAREST
86
+ *************************************************************
87
+ *************************************************************/
88
+ double log2_rn(double x) {
89
+ scs_t R, res1, sc_exp;
90
+ scs_ptr inv_wi, ti;
91
+
92
+ db_number nb, nb2, wi, resd;
93
+ int i, E=0;
94
+
95
+ nb.d = x;
96
+ /* Filter cases */
97
+ if (nb.i[HI] < 0x00100000){ /* x < 2^(-1022) */
98
+ if (((nb.i[HI] & 0x7fffffff)|nb.i[LO])==0)
99
+ return 1.0/0.0; /* log(+/-0) = -Inf */
100
+ if (nb.i[HI] < 0)
101
+ return (x-x)/0; /* log(-x) = Nan */
102
+
103
+ /* Subnormal number */
104
+ E -= (SCS_NB_BITS*2); /* keep in mind that x is a subnormal number */
105
+ nb.d *=SCS_RADIX_TWO_DOUBLE; /* make x as normal number */
106
+ /* We may just want add 2 to the scs number.index */
107
+ /* may be .... we will see */
108
+ }
109
+ if (nb.i[HI] >= 0x7ff00000)
110
+ return x+x; /* Inf or Nan */
111
+
112
+ /* find n, nb.d such that sqrt(2)/2 < nb.d < sqrt(2) */
113
+ E += (nb.i[HI]>>20)-1023;
114
+ nb.i[HI] = (nb.i[HI] & 0x000fffff) | 0x3ff00000;
115
+ if (nb.d > SQRT_2){
116
+ nb.d *= 0.5;
117
+ E++;
118
+ }
119
+
120
+ scs_set_si(sc_exp, E);
121
+
122
+ /* to normalize nb.d and round to nearest */
123
+ /* +((2^4 - trunc(sqrt(2)/2) *2^4 )*2 + 1)/2^5 */
124
+ nb2.d = nb.d + norm_number.d;
125
+ i = (nb2.i[HI] & 0x000fffff);
126
+ i = i >> 16; /* 0<= i <=11 */
127
+
128
+ wi.d = (11+i)*(double)0.6250e-1;
129
+
130
+ /* (1+f-w_i) */
131
+ nb.d -= wi.d;
132
+
133
+ /* Table reduction */
134
+ ti = table_ti_ptr[i];
135
+ inv_wi = table_inv_wi_ptr[i];
136
+
137
+
138
+ /* R = (1+f-w_i)/w_i */
139
+ scs_set_d(R, nb.d);
140
+ scs_mul(R, R, inv_wi);
141
+
142
+
143
+ /*
144
+ * Polynomial evaluation of log2(1 + R) with an error less than 2^(-130)
145
+ */
146
+ scs_mul(res1, constant_poly_ptr[0], R);
147
+ for(i=1; i<20; i++){
148
+ scs_add(res1, constant_poly_ptr[i], res1);
149
+ scs_mul(res1, res1, R);
150
+ }
151
+ scs_add(res1, res1, ti);
152
+ scs_add(res1, res1, sc_exp);
153
+
154
+ scs_get_d(&resd.d, res1);
155
+
156
+ return resd.d;
157
+ }
158
+
159
+
160
+
161
+
162
+
163
+ /*************************************************************
164
+ *************************************************************
165
+ * ROUNDED TOWARD -INFINITY
166
+ *************************************************************
167
+ *************************************************************/
168
+ double log2_rd(double x) {
169
+ scs_t R, res1, sc_exp;
170
+ scs_ptr inv_wi, ti;
171
+
172
+ db_number nb, nb2, wi, resd;
173
+ int i, E=0;
174
+
175
+ nb.d = x;
176
+ /* Filter cases */
177
+ if (nb.i[HI] < 0x00100000){ /* x < 2^(-1022) */
178
+ if (((nb.i[HI] & 0x7fffffff)|nb.i[LO])==0)
179
+ return 1.0/0.0; /* log(+/-0) = -Inf */
180
+ if (nb.i[HI] < 0)
181
+ return (x-x)/0; /* log(-x) = Nan */
182
+
183
+ /* Subnormal number */
184
+ E -= (SCS_NB_BITS*2); /* keep in mind that x is a subnormal number */
185
+ nb.d *=SCS_RADIX_TWO_DOUBLE; /* make x as normal number */
186
+ /* We may just want add 2 to the scs number.index */
187
+ /* may be .... we will see */
188
+ }
189
+ if (nb.i[HI] >= 0x7ff00000)
190
+ return x+x; /* Inf or Nan */
191
+
192
+ /* find n, nb.d such that sqrt(2)/2 < nb.d < sqrt(2) */
193
+ E += (nb.i[HI]>>20)-1023;
194
+ nb.i[HI] = (nb.i[HI] & 0x000fffff) | 0x3ff00000;
195
+ if (nb.d > SQRT_2){
196
+ nb.d *= 0.5;
197
+ E++;
198
+ }
199
+
200
+ scs_set_si(sc_exp, E);
201
+
202
+ /* to normalize nb.d and round to nearest */
203
+ /* +((2^4 - trunc(sqrt(2)/2) *2^4 )*2 + 1)/2^5 */
204
+ nb2.d = nb.d + norm_number.d;
205
+ i = (nb2.i[HI] & 0x000fffff);
206
+ i = i >> 16; /* 0<= i <=11 */
207
+
208
+ wi.d = (11+i)*(double)0.6250e-1;
209
+
210
+ /* (1+f-w_i) */
211
+ nb.d -= wi.d;
212
+
213
+ /* Table reduction */
214
+ ti = table_ti_ptr[i];
215
+ inv_wi = table_inv_wi_ptr[i];
216
+
217
+
218
+ /* R = (1+f-w_i)/w_i */
219
+ scs_set_d(R, nb.d);
220
+ scs_mul(R, R, inv_wi);
221
+
222
+
223
+ /*
224
+ * Polynomial evaluation of log2(1 + R) with an error less than 2^(-130)
225
+ */
226
+ scs_mul(res1, constant_poly_ptr[0], R);
227
+ for(i=1; i<20; i++){
228
+ scs_add(res1, constant_poly_ptr[i], res1);
229
+ scs_mul(res1, res1, R);
230
+ }
231
+ scs_add(res1, res1, ti);
232
+ scs_add(res1, res1, sc_exp);
233
+
234
+ scs_get_d_minf(&resd.d, res1);
235
+
236
+ return resd.d;
237
+ }
238
+
239
+
240
+
241
+
242
+
243
+
244
+ /*************************************************************
245
+ *************************************************************
246
+ * ROUNDED TOWARD +INFINITY
247
+ *************************************************************
248
+ *************************************************************/
249
+ double log2_ru(double x) {
250
+ scs_t R, res1, sc_exp;
251
+ scs_ptr inv_wi, ti;
252
+
253
+ db_number nb, nb2, wi, resd;
254
+ int i, E=0;
255
+
256
+ nb.d = x;
257
+ /* Filter cases */
258
+ if (nb.i[HI] < 0x00100000){ /* x < 2^(-1022) */
259
+ if (((nb.i[HI] & 0x7fffffff)|nb.i[LO])==0)
260
+ return 1.0/0.0; /* log(+/-0) = -Inf */
261
+ if (nb.i[HI] < 0)
262
+ return (x-x)/0; /* log(-x) = Nan */
263
+
264
+ /* Subnormal number */
265
+ E -= (SCS_NB_BITS*2); /* keep in mind that x is a subnormal number */
266
+ nb.d *=SCS_RADIX_TWO_DOUBLE; /* make x as normal number */
267
+ /* We may just want add 2 to the scs number.index */
268
+ /* may be .... we will see */
269
+ }
270
+ if (nb.i[HI] >= 0x7ff00000)
271
+ return x+x; /* Inf or Nan */
272
+
273
+ /* find n, nb.d such that sqrt(2)/2 < nb.d < sqrt(2) */
274
+ E += (nb.i[HI]>>20)-1023;
275
+ nb.i[HI] = (nb.i[HI] & 0x000fffff) | 0x3ff00000;
276
+ if (nb.d > SQRT_2){
277
+ nb.d *= 0.5;
278
+ E++;
279
+ }
280
+
281
+ scs_set_si(sc_exp, E);
282
+
283
+ /* to normalize nb.d and round to nearest */
284
+ /* +((2^4 - trunc(sqrt(2)/2) *2^4 )*2 + 1)/2^5 */
285
+ nb2.d = nb.d + norm_number.d;
286
+ i = (nb2.i[HI] & 0x000fffff);
287
+ i = i >> 16; /* 0<= i <=11 */
288
+
289
+ wi.d = (11+i)*(double)0.6250e-1;
290
+
291
+ /* (1+f-w_i) */
292
+ nb.d -= wi.d;
293
+
294
+ /* Table reduction */
295
+ ti = table_ti_ptr[i];
296
+ inv_wi = table_inv_wi_ptr[i];
297
+
298
+
299
+ /* R = (1+f-w_i)/w_i */
300
+ scs_set_d(R, nb.d);
301
+ scs_mul(R, R, inv_wi);
302
+
303
+
304
+ /*
305
+ * Polynomial evaluation of log2(1 + R) with an error less than 2^(-130)
306
+ */
307
+ scs_mul(res1, constant_poly_ptr[0], R);
308
+ for(i=1; i<20; i++){
309
+ scs_add(res1, constant_poly_ptr[i], res1);
310
+ scs_mul(res1, res1, R);
311
+ }
312
+ scs_add(res1, res1, ti);
313
+ scs_add(res1, res1, sc_exp);
314
+
315
+ scs_get_d_pinf(&resd.d, res1);
316
+
317
+ return resd.d;
318
+ }
319
+
320
+ /*************************************************************
321
+ *************************************************************
322
+ * ROUNDED TOWARDS ZERO
323
+ *************************************************************
324
+ *************************************************************/
325
+ double log2_rz(double x) {
326
+ if (x > 1)
327
+ return log2_rd(x);
328
+ else
329
+ return log2_ru(x);
330
+ }
@@ -0,0 +1,261 @@
1
+ #include "crlibm.h"
2
+ #include "crlibm_private.h"
3
+ /*
4
+ * Constant to compute the logarithm base 2.
5
+ */
6
+ #ifdef WORDS_BIGENDIAN
7
+ static const db_number
8
+ norm_number = {{0x3FD60000, 0x00000000}}; /* 11*2^(-5) */
9
+ #else
10
+ static const db_number
11
+ norm_number = {{0x00000000, 0x3FD60000}}; /* 11*2^(-5) */
12
+ #endif
13
+
14
+
15
+ static const scs table_ti[13]=
16
+ /* ~-5.405684e-01 */
17
+ {{{0x2298ac1f, 0x33457c40, 0x1c141e66, 0x3eaaab29,
18
+ 0x1030633d, 0x048bef17, 0x1a91d6a1, 0x22230522},
19
+ DB_ONE, -1, -1 }
20
+ ,
21
+ /* ~-4.150375e-01 */
22
+ {{0x1a8ff971, 0x20429786, 0x017fd3b7, 0x35f97452,
23
+ 0x0bb6c306, 0x15c5da64, 0x3efe1069, 0x2fb2da05},
24
+ DB_ONE, -1, -1 }
25
+ ,
26
+ /* ~-2.995603e-01 */
27
+ {{0x132bfee3, 0x1c3b9a19, 0x1a24978d, 0x38d67cae,
28
+ 0x3878c2df, 0x02d6ff98, 0x24e1a2a9, 0x1b4f917d},
29
+ DB_ONE, -1, -1 }
30
+ ,
31
+ /* ~-1.926451e-01 */
32
+ {{0x0c544c05, 0x17f7a64c, 0x3354dbf1, 0x1bec1a57,
33
+ 0x2e31ce56, 0x2b7fe8e9, 0x20d510a7, 0x19e262f3},
34
+ DB_ONE, -1, -1 }
35
+ ,
36
+ /* ~-9.310940e-02 */
37
+ {{0x05f58125, 0x2cfbb4c6, 0x1ced1447, 0x38c2b4e4,
38
+ 0x3edd56b0, 0x1637ed79, 0x2a14f4fe, 0x3db0ce67},
39
+ DB_ONE, -1, -1 }
40
+ ,
41
+ /* ZERO */
42
+ {{0x00000000, 0x00000000, 0x00000000, 0x00000000,
43
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000},
44
+ {{0, 0}}, 0, 1 }
45
+ ,
46
+ /* ~8.746284e-02 */
47
+ {{0x0598fdbe, 0x2c913167, 0x33314e09, 0x2144575a,
48
+ 0x30f2941f, 0x0fab1d27, 0x3e612491, 0x0849fe51},
49
+ DB_ONE, -1, 1 }
50
+ ,
51
+ /* ~1.699250e-01 */
52
+ {{0x0ae00d1c, 0x3f7ad0f3, 0x3d005890, 0x140d175b,
53
+ 0x289279f3, 0x14744b36, 0x0203df2c, 0x209a4bf4},
54
+ DB_ONE, -1, 1 }
55
+ ,
56
+ /* ~2.479275e-01 */
57
+ {{0x0fde0b5c, 0x204d0144, 0x1d46ccc5, 0x0f09de6b,
58
+ 0x39267ab7, 0x1b5a9520, 0x35aacfb1, 0x311d7642},
59
+ DB_ONE, -1, 1 }
60
+ ,
61
+ /* ~3.219281e-01 */
62
+ {{0x149a784b, 0x3346e2bf, 0x2492bf6f, 0x3d36bf6d,
63
+ 0x0cd96c55, 0x3f8deceb, 0x14e91b6a, 0x32020b9e},
64
+ DB_ONE, -1, 1 }
65
+ ,
66
+ /* ~3.923174e-01 */
67
+ {{0x191bba89, 0x07c5c22d, 0x0b2b5056, 0x2e1a7156,
68
+ 0x06176ea2, 0x3eba3cb1, 0x202cdeee, 0x366ac306},
69
+ DB_ONE, -1, 1 }
70
+ ,
71
+ /* ~4.594316e-01 */
72
+ {{0x1d6753e0, 0x0cba83bf, 0x23ebe199, 0x015554d6,
73
+ 0x2fcf9cc2, 0x3b7410e8, 0x256e295e, 0x1ddcfadd},
74
+ DB_ONE, -1, 1 }
75
+ ,
76
+ /* ~5.235620e-01 */
77
+ {{0x21820a01, 0x2b1d532c, 0x104aea53, 0x1b12ef0a,
78
+ 0x2a0fca1a, 0x1dd6be1d, 0x0730b711, 0x35eaa979},
79
+ DB_ONE, -1, 1 }
80
+ };
81
+
82
+
83
+
84
+ static const scs table_inv_wi[13]=
85
+ /* ~1.454545e+00 */
86
+ {{{0x00000001, 0x1d1745d1, 0x1d1745d1, 0x1d1745d1,
87
+ 0x1d1745d1, 0x1d1745d1, 0x1d183e2a, 0x36835582},
88
+ DB_ONE, 0, 1 }
89
+ ,
90
+ /* ~1.333333e+00 */
91
+ {{0x00000001, 0x15555555, 0x15555555, 0x15555555,
92
+ 0x15555555, 0x15555555, 0x15549b7e, 0x1a416c6b},
93
+ DB_ONE, 0, 1 }
94
+ ,
95
+ /* ~1.230769e+00 */
96
+ {{0x00000001, 0x0ec4ec4e, 0x313b13b1, 0x0ec4ec4e,
97
+ 0x313b13b1, 0x0ec4ec4e, 0x313a6825, 0x3ab28b77},
98
+ DB_ONE, 0, 1 }
99
+ ,
100
+ /* ~1.142857e+00 */
101
+ {{0x00000001, 0x09249249, 0x09249249, 0x09249249,
102
+ 0x09249249, 0x09249249, 0x09238b74, 0x26f620a6},
103
+ DB_ONE, 0, 1 }
104
+ ,
105
+ /* ~1.066667e+00 */
106
+ {{0x00000001, 0x04444444, 0x11111111, 0x04444444,
107
+ 0x11111111, 0x04444444, 0x1111d60e, 0x1f0c9d58},
108
+ DB_ONE, 0, 1 }
109
+ ,
110
+ /* ~1.000000e+00 */
111
+ {{0x00000001, 0x00000000, 0x00000000, 0x00000000,
112
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000},
113
+ DB_ONE, 0, 1 }
114
+ ,
115
+ /* ~9.411765e-01 */
116
+ {{0x3c3c3c3c, 0x0f0f0f0f, 0x03c3c3c3, 0x30f0f0f0,
117
+ 0x3c3c3c3c, 0x0f0f923d, 0x16e0e0a4, 0x3a84202f},
118
+ DB_ONE, -1, 1 }
119
+ ,
120
+ /* ~8.888889e-01 */
121
+ {{0x38e38e38, 0x38e38e38, 0x38e38e38, 0x38e38e38,
122
+ 0x38e38e38, 0x38e3946a, 0x2e0ee2c9, 0x0d6e0fbd},
123
+ DB_ONE, -1, 1 }
124
+ ,
125
+ /* ~8.421053e-01 */
126
+ {{0x35e50d79, 0x10d79435, 0x39435e50, 0x35e50d79,
127
+ 0x10d79435, 0x3943324d, 0x0637ea85, 0x131a67ba},
128
+ DB_ONE, -1, 1 }
129
+ ,
130
+ /* ~8.000000e-01 */
131
+ {{0x33333333, 0x0ccccccc, 0x33333333, 0x0ccccccc,
132
+ 0x33333333, 0x0ccccccc, 0x33333333, 0x0ccccccc},
133
+ DB_ONE, -1, 1 }
134
+ ,
135
+ /* ~7.619048e-01 */
136
+ {{0x30c30c30, 0x30c30c30, 0x30c30c30, 0x30c30c30,
137
+ 0x30c30c30, 0x30c2f1a4, 0x160958a1, 0x2b03bc88},
138
+ DB_ONE, -1, 1 }
139
+ ,
140
+ /* ~7.272727e-01 */
141
+ {{0x2e8ba2e8, 0x2e8ba2e8, 0x2e8ba2e8, 0x2e8ba2e8,
142
+ 0x2e8ba2e8, 0x2e8bcb74, 0x2d78b525, 0x00a1db67},
143
+ DB_ONE, -1, 1 }
144
+ ,
145
+ /* ~6.956522e-01 */
146
+ {{0x2c8590b2, 0x0590b216, 0x10b21642, 0x321642c8,
147
+ 0x1642c859, 0x02c8590b, 0x08590b21, 0x190b2164},
148
+ DB_ONE, -1, 1 }
149
+ };
150
+
151
+
152
+
153
+
154
+
155
+
156
+ static const scs constant_poly[20]=
157
+ /* ~-7.247187e-02 */
158
+ {{{0x04a3610e, 0x3280f22f, 0x1de04b83, 0x13d0592c,
159
+ 0x01c1f347, 0x0e59a808, 0x0bcf5cfa, 0x3009a167},
160
+ DB_ONE, -1, -1 }
161
+ ,
162
+ /* ~7.626763e-02 */
163
+ {{0x04e191a1, 0x27127aea, 0x2fb498c3, 0x3f8e3721,
164
+ 0x2688ed52, 0x38503e4f, 0x3b216e42, 0x17d8666c},
165
+ DB_ONE, -1, 1 }
166
+ ,
167
+ /* ~-8.014898e-02 */
168
+ {{0x05212933, 0x12c0276e, 0x1534c74e, 0x1ffc3802,
169
+ 0x36935f91, 0x25fe848d, 0x2bade416, 0x110f0662},
170
+ DB_ONE, -1, -1 }
171
+ ,
172
+ /* ~8.486372e-02 */
173
+ {{0x056e6838, 0x35aa4f4a, 0x2ae2f258, 0x30768483,
174
+ 0x2bc43d6e, 0x176d2fe1, 0x17488263, 0x30f7670b},
175
+ DB_ONE, -1, 1 }
176
+ ,
177
+ /* ~-9.016844e-02 */
178
+ {{0x05c551da, 0x1166e535, 0x10625f98, 0x08af81ee,
179
+ 0x04feb59e, 0x2906123e, 0x0b31f878, 0x0693beb1},
180
+ DB_ONE, -1, -1 }
181
+ ,
182
+ /* ~9.617967e-02 */
183
+ {{0x0627cec6, 0x20792d0d, 0x181b90ab, 0x0c8e3405,
184
+ 0x1fe3b53f, 0x0f6d3b7a, 0x00eefd12, 0x0808849b},
185
+ DB_ONE, -1, 1 }
186
+ ,
187
+ /* ~-1.030496e-01 */
188
+ {{0x06985d8a, 0x27a1d37d, 0x3fa3c0e9, 0x37e7d679,
189
+ 0x0379ed1d, 0x25a15e16, 0x3ef8c491, 0x2414ab4f},
190
+ DB_ONE, -1, -1 }
191
+ ,
192
+ /* ~1.109765e-01 */
193
+ {{0x071a3d5a, 0x0d27a702, 0x138411a6, 0x15701cae,
194
+ 0x31ef415d, 0x1985227d, 0x31a4c54c, 0x15d3a279},
195
+ DB_ONE, -1, 1 }
196
+ ,
197
+ /* ~-1.202246e-01 */
198
+ {{0x07b1c277, 0x03a04150, 0x3be8d05b, 0x2f373cf4,
199
+ 0x105c73c2, 0x0ee0272b, 0x0b2bf018, 0x1ad7026f},
200
+ DB_ONE, -1, -1 }
201
+ ,
202
+ /* ~1.311541e-01 */
203
+ {{0x0864d424, 0x328046b9, 0x132f0fc6, 0x2b14d554,
204
+ 0x189d4b79, 0x2ec40035, 0x15083d44, 0x33a13b8c},
205
+ DB_ONE, -1, 1 }
206
+ ,
207
+ /* ~-1.442695e-01 */
208
+ {{0x093bb628, 0x1df37fcf, 0x022eb69a, 0x0b325d1d,
209
+ 0x0625c904, 0x1ccaa7ae, 0x0ed7ce1d, 0x3202ff74},
210
+ DB_ONE, -1, -1 }
211
+ ,
212
+ /* ~1.602994e-01 */
213
+ {{0x0a42589e, 0x2f80551e, 0x3eb3ec54, 0x1a1094cd,
214
+ 0x23649796, 0x328d4019, 0x3f6371c6, 0x37a359a1},
215
+ DB_ONE, -1, 1 }
216
+ ,
217
+ /* ~-1.803369e-01 */
218
+ {{0x0b8aa3b2, 0x25705fc2, 0x3bbedcca, 0x35a13588,
219
+ 0x15c06cdc, 0x39fbf52c, 0x2b666451, 0x350d8287},
220
+ DB_ONE, -1, -1 }
221
+ ,
222
+ /* ~2.060993e-01 */
223
+ {{0x0d30bb15, 0x0f5bdb27, 0x3b23121c, 0x383c6bb0,
224
+ 0x2f3b4fd2, 0x2dba0ce0, 0x0230a445, 0x306b1136},
225
+ DB_ONE, -1, 1 }
226
+ ,
227
+ /* ~-2.404492e-01 */
228
+ {{0x0f6384ee, 0x07407fae, 0x24fe0aa6, 0x3c7aefd2,
229
+ 0x12953456, 0x0d1d1991, 0x2af86714, 0x26b4c925},
230
+ DB_ONE, -1, -1 }
231
+ ,
232
+ /* ~2.885390e-01 */
233
+ {{0x12776c50, 0x3be6ff9e, 0x12ca7330, 0x1a6d448b,
234
+ 0x1ef18433, 0x375e9366, 0x21f2efcf, 0x38ab1d93},
235
+ DB_ONE, -1, 1 }
236
+ ,
237
+ /* ~-3.606738e-01 */
238
+ {{0x17154765, 0x0ae0bf85, 0x377d0ffd, 0x2836248a,
239
+ 0x3b8e6858, 0x123f10ae, 0x0c65387c, 0x26048456},
240
+ DB_ONE, -1, -1 }
241
+ ,
242
+ /* ~4.808983e-01 */
243
+ {{0x1ec709dc, 0x0e80ff5d, 0x09fc1552, 0x0af12c97,
244
+ 0x37bd6a2c, 0x3ebc8f65, 0x113a7c28, 0x1663571a},
245
+ DB_ONE, -1, 1 }
246
+ ,
247
+ /* ~-7.213475e-01 */
248
+ {{0x2e2a8eca, 0x15c17f0b, 0x2efa1ffb, 0x10691d3d,
249
+ 0x09a93721, 0x2d59e835, 0x1baea424, 0x28b120a0},
250
+ DB_ONE, -1, -1 }
251
+ ,
252
+ /* ~1.442695e+00 */
253
+ {{0x00000001, 0x1c551d94, 0x2b82fe17, 0x1df43ff6,
254
+ 0x20d23a7c, 0x3b9ff352, 0x14d59cbf, 0x00fe1bdb},
255
+ DB_ONE, 0, 1 }
256
+ };
257
+
258
+
259
+ #define constant_poly_ptr (scs_ptr)&constant_poly
260
+ #define table_ti_ptr (scs_ptr)&table_ti
261
+ #define table_inv_wi_ptr (scs_ptr)&table_inv_wi
@@ -0,0 +1,133 @@
1
+ /*
2
+ * Correctly rounded logarithm
3
+ *
4
+ * Author : David Defour
5
+ *
6
+ * This file is part of the crlibm library developed by the Arenaire
7
+ * project at Ecole Normale Superieure de Lyon
8
+ *
9
+ * This program is free software; you can redistribute it and/or modify
10
+ * it under the terms of the GNU Lesser General Public License as published by
11
+ * the Free Software Foundation; either version 2 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public License
20
+ * along with this program; if not, write to the Free Software
21
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
+ */
23
+ #include <stdio.h>
24
+ #include "log_accurate.h"
25
+
26
+ /*
27
+ * 1) First reduction: exponent extraction
28
+ * E
29
+ * x = 2^ .(1+f) with 0 <= f < 1
30
+ *
31
+ * log(x) = E.log(2) + log(1+f) where:
32
+ * - log(2) is tabulated
33
+ * - log(1+f) need to be evaluated
34
+ *
35
+ *
36
+ * 2) Avoiding accuracy problem when E=-1 by testing
37
+ *
38
+ * if (1+f >= sqrt(2)) then
39
+ * 1+f = (1+f)/2; E = E+1;
40
+ * and,
41
+ * log(x) = (E+1).log(2) + log((1+f)/2)
42
+ *
43
+ * so now: sqrt(2)/2 <= (1+f) < sqrt(2)
44
+ *
45
+ *
46
+ * 3) Second reduction: tabular reduction
47
+ * -4
48
+ * wi = 1 + i. 2^
49
+ * 1
50
+ * log(1+f) = log(wi) + log ( 1 + --- . (1 + f - wi) )
51
+ * wi
52
+ *
53
+ * then |(1+f-wi)/wi| <= 2^-5 if we use rounded to nearest.
54
+ *
55
+ * 4) Computation:
56
+ * a) Table lookup of:
57
+ * - ti = log(wi)
58
+ * - inv_wi = 1/(wi)
59
+ * b) Polynomial evaluation of:
60
+ * - P(R) ~ log(1 + R), where R = (1+f-wi) * inv_wi
61
+ *
62
+ * -5
63
+ * with |R| < 2^
64
+ *
65
+ *
66
+ * 5) Reconstruction:
67
+ * log(x) = E.log(2) + t_i + P(R)
68
+ *
69
+ */
70
+
71
+
72
+
73
+
74
+ void scs_log(scs_ptr res, db_number y, int E){
75
+ scs_t R, sc_ln2_times_E, res1, addi;
76
+ scs_ptr ti, inv_wi;
77
+ db_number z, wi;
78
+ int i;
79
+
80
+
81
+ #if EVAL_PERF
82
+ crlibm_second_step_taken++;
83
+ #endif
84
+
85
+
86
+ /* to normalize y.d and round to nearest */
87
+ /* + (1-trunc(sqrt(2.)/2 * 2^(4))*2^(-4) )+2.^(-(4+1))*/
88
+ z.d = y.d + norm_number.d;
89
+ i = (z.i[HI] & 0x000fffff);
90
+ i = i >> 16; /* 0<= i <=11 */
91
+
92
+
93
+ wi.d = ((double)(11+i))*0.0625;
94
+
95
+ /* (1+f-w_i) */
96
+ y.d -= wi.d;
97
+
98
+ /* Table reduction */
99
+ ti = table_ti_ptr[i];
100
+ inv_wi = table_inv_wi_ptr[i];
101
+
102
+ /* R = (1+f-w_i)/w_i */
103
+ scs_set_d(R, y.d);
104
+ scs_mul(R, R, inv_wi);
105
+
106
+
107
+ /*
108
+ * Polynomial evaluation of log(1 + R) with an error less than 2^(-130)
109
+ */
110
+
111
+ scs_mul(res1, constant_poly_ptr[0], R);
112
+ for(i=1; i<20; i++){
113
+ scs_add(addi, constant_poly_ptr[i], res1);
114
+ scs_mul(res1, addi, R);
115
+ }
116
+
117
+ if(E==0){
118
+ scs_add(res, res1, ti);
119
+ }else{
120
+ /* sc_ln2_times_E = E*log(2) */
121
+ scs_set(sc_ln2_times_E, sc_ln2_ptr);
122
+
123
+ if (E >= 0){
124
+ scs_mul_ui(sc_ln2_times_E, (unsigned int) E);
125
+ }else{
126
+ scs_mul_ui(sc_ln2_times_E, (unsigned int) -E);
127
+ sc_ln2_times_E->sign = -1;
128
+ }
129
+ scs_add(addi, res1, ti);
130
+ scs_add(res, addi, sc_ln2_times_E);
131
+ }
132
+ }
133
+