intervals 0.3.56

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/VERSION.txt +1 -0
  2. data/ext/crlibm/AUTHORS +2 -0
  3. data/ext/crlibm/COPYING +504 -0
  4. data/ext/crlibm/ChangeLog +80 -0
  5. data/ext/crlibm/INSTALL +182 -0
  6. data/ext/crlibm/Makefile.am +84 -0
  7. data/ext/crlibm/Makefile.in +530 -0
  8. data/ext/crlibm/NEWS +0 -0
  9. data/ext/crlibm/README +31 -0
  10. data/ext/crlibm/TODO +47 -0
  11. data/ext/crlibm/VERSION +1 -0
  12. data/ext/crlibm/aclocal.m4 +989 -0
  13. data/ext/crlibm/atan-itanium.c +846 -0
  14. data/ext/crlibm/atan-pentium.c +261 -0
  15. data/ext/crlibm/atan_accurate.c +244 -0
  16. data/ext/crlibm/atan_accurate.h +191 -0
  17. data/ext/crlibm/atan_fast.c +324 -0
  18. data/ext/crlibm/atan_fast.h +678 -0
  19. data/ext/crlibm/config.guess +1461 -0
  20. data/ext/crlibm/config.sub +1566 -0
  21. data/ext/crlibm/configure +7517 -0
  22. data/ext/crlibm/configure.ac +364 -0
  23. data/ext/crlibm/crlibm.h +125 -0
  24. data/ext/crlibm/crlibm_config.h +149 -0
  25. data/ext/crlibm/crlibm_config.h.in +148 -0
  26. data/ext/crlibm/crlibm_private.c +293 -0
  27. data/ext/crlibm/crlibm_private.h +658 -0
  28. data/ext/crlibm/csh_fast.c +631 -0
  29. data/ext/crlibm/csh_fast.h +771 -0
  30. data/ext/crlibm/double-extended.h +496 -0
  31. data/ext/crlibm/exp-td.c +962 -0
  32. data/ext/crlibm/exp-td.h +685 -0
  33. data/ext/crlibm/exp_accurate.c +197 -0
  34. data/ext/crlibm/exp_accurate.h +85 -0
  35. data/ext/crlibm/gappa/log-de-E0-logir0.gappa +106 -0
  36. data/ext/crlibm/gappa/log-de-E0.gappa +79 -0
  37. data/ext/crlibm/gappa/log-de.gappa +81 -0
  38. data/ext/crlibm/gappa/log-td-E0-logir0.gappa +126 -0
  39. data/ext/crlibm/gappa/log-td-E0.gappa +143 -0
  40. data/ext/crlibm/gappa/log-td-accurate-E0-logir0.gappa +230 -0
  41. data/ext/crlibm/gappa/log-td-accurate-E0.gappa +213 -0
  42. data/ext/crlibm/gappa/log-td-accurate.gappa +217 -0
  43. data/ext/crlibm/gappa/log-td.gappa +156 -0
  44. data/ext/crlibm/gappa/trigoSinCosCase3.gappa +204 -0
  45. data/ext/crlibm/gappa/trigoTanCase2.gappa +73 -0
  46. data/ext/crlibm/install-sh +269 -0
  47. data/ext/crlibm/log-de.c +431 -0
  48. data/ext/crlibm/log-de.h +732 -0
  49. data/ext/crlibm/log-td.c +852 -0
  50. data/ext/crlibm/log-td.h +819 -0
  51. data/ext/crlibm/log10-td.c +906 -0
  52. data/ext/crlibm/log10-td.h +823 -0
  53. data/ext/crlibm/log2-td.c +935 -0
  54. data/ext/crlibm/log2-td.h +821 -0
  55. data/ext/crlibm/maple/atan.mpl +359 -0
  56. data/ext/crlibm/maple/common-procedures.mpl +997 -0
  57. data/ext/crlibm/maple/csh.mpl +446 -0
  58. data/ext/crlibm/maple/double-extended.mpl +151 -0
  59. data/ext/crlibm/maple/exp-td.mpl +195 -0
  60. data/ext/crlibm/maple/log-de.mpl +243 -0
  61. data/ext/crlibm/maple/log-td.mpl +316 -0
  62. data/ext/crlibm/maple/log10-td.mpl +345 -0
  63. data/ext/crlibm/maple/log2-td.mpl +334 -0
  64. data/ext/crlibm/maple/trigo.mpl +728 -0
  65. data/ext/crlibm/maple/triple-double.mpl +58 -0
  66. data/ext/crlibm/missing +198 -0
  67. data/ext/crlibm/mkinstalldirs +40 -0
  68. data/ext/crlibm/rem_pio2_accurate.c +219 -0
  69. data/ext/crlibm/rem_pio2_accurate.h +53 -0
  70. data/ext/crlibm/scs_lib/AUTHORS +3 -0
  71. data/ext/crlibm/scs_lib/COPYING +504 -0
  72. data/ext/crlibm/scs_lib/ChangeLog +16 -0
  73. data/ext/crlibm/scs_lib/INSTALL +215 -0
  74. data/ext/crlibm/scs_lib/Makefile.am +18 -0
  75. data/ext/crlibm/scs_lib/Makefile.in +328 -0
  76. data/ext/crlibm/scs_lib/NEWS +0 -0
  77. data/ext/crlibm/scs_lib/README +9 -0
  78. data/ext/crlibm/scs_lib/TODO +4 -0
  79. data/ext/crlibm/scs_lib/addition_scs.c +623 -0
  80. data/ext/crlibm/scs_lib/config.guess +1461 -0
  81. data/ext/crlibm/scs_lib/config.sub +1566 -0
  82. data/ext/crlibm/scs_lib/configure +6226 -0
  83. data/ext/crlibm/scs_lib/division_scs.c +110 -0
  84. data/ext/crlibm/scs_lib/double2scs.c +174 -0
  85. data/ext/crlibm/scs_lib/install-sh +269 -0
  86. data/ext/crlibm/scs_lib/missing +198 -0
  87. data/ext/crlibm/scs_lib/mkinstalldirs +40 -0
  88. data/ext/crlibm/scs_lib/multiplication_scs.c +456 -0
  89. data/ext/crlibm/scs_lib/poly_fct.c +112 -0
  90. data/ext/crlibm/scs_lib/print_scs.c +73 -0
  91. data/ext/crlibm/scs_lib/rand_scs.c +63 -0
  92. data/ext/crlibm/scs_lib/scs.h +353 -0
  93. data/ext/crlibm/scs_lib/scs2double.c +391 -0
  94. data/ext/crlibm/scs_lib/scs2mpf.c +58 -0
  95. data/ext/crlibm/scs_lib/scs2mpfr.c +61 -0
  96. data/ext/crlibm/scs_lib/scs_private.c +23 -0
  97. data/ext/crlibm/scs_lib/scs_private.h +133 -0
  98. data/ext/crlibm/scs_lib/tests/tbx_timing.h +102 -0
  99. data/ext/crlibm/scs_lib/wrapper_scs.h +486 -0
  100. data/ext/crlibm/scs_lib/zero_scs.c +52 -0
  101. data/ext/crlibm/stamp-h.in +1 -0
  102. data/ext/crlibm/tests/Makefile.am +43 -0
  103. data/ext/crlibm/tests/Makefile.in +396 -0
  104. data/ext/crlibm/tests/blind_test.c +148 -0
  105. data/ext/crlibm/tests/generate_test_vectors.c +258 -0
  106. data/ext/crlibm/tests/soak_test.c +334 -0
  107. data/ext/crlibm/tests/test_common.c +627 -0
  108. data/ext/crlibm/tests/test_common.h +28 -0
  109. data/ext/crlibm/tests/test_perf.c +570 -0
  110. data/ext/crlibm/tests/test_val.c +249 -0
  111. data/ext/crlibm/trigo_accurate.c +500 -0
  112. data/ext/crlibm/trigo_accurate.h +331 -0
  113. data/ext/crlibm/trigo_fast.c +1219 -0
  114. data/ext/crlibm/trigo_fast.h +639 -0
  115. data/ext/crlibm/triple-double.h +878 -0
  116. data/ext/extconf.rb +31 -0
  117. data/ext/fpu.c +107 -0
  118. data/ext/jamis-mod.rb +591 -0
  119. data/lib/fpu.rb +287 -0
  120. data/lib/interval.rb +1170 -0
  121. data/lib/intervals.rb +212 -0
  122. data/lib/struct_float.rb +133 -0
  123. data/test/data_atan.txt +360 -0
  124. data/test/data_cos.txt +346 -0
  125. data/test/data_cosh.txt +3322 -0
  126. data/test/data_exp.txt +3322 -0
  127. data/test/data_log.txt +141 -0
  128. data/test/data_sin.txt +140 -0
  129. data/test/data_sinh.txt +3322 -0
  130. data/test/data_tan.txt +342 -0
  131. metadata +186 -0
@@ -0,0 +1,500 @@
1
+ /*
2
+ * Correctly rounded trigonometric functions
3
+ *
4
+ * Author : Catherine Daramy, David Defour, Florent de Dinechin
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 <stdlib.h>
25
+ #include "trigo_accurate.h"
26
+
27
+
28
+ /*
29
+ *
30
+ * 1) Range reduction if needed ... x in [-Pi/4, +Pi/4]
31
+ *
32
+ * 2) call cosine, sine or tan polynomial
33
+ *
34
+ * Polynomials are vastly too accurate.
35
+ */
36
+
37
+
38
+
39
+
40
+
41
+ /* Polynomial evaluation of sin(x) over [-Pi/4, +Pi/4]
42
+ Approximation error lower than 2^(-133) */
43
+
44
+ static void scs_sin(scs_ptr x){
45
+ scs_t res_scs;
46
+ scs_t x2;
47
+ int i;
48
+
49
+ scs_square(x2, x);
50
+ scs_mul(res_scs, sin_scs_poly_ptr[0], x2);
51
+
52
+ for(i=1; i<(DEGREE_SIN_SCS-1)/2; i++){ /* Last coeff is one, not read from the file*/
53
+ scs_add(res_scs, sin_scs_poly_ptr[i], res_scs);
54
+ scs_mul(res_scs, res_scs, x2);
55
+ }
56
+ scs_mul(res_scs, res_scs, x);
57
+ scs_add(x, x, res_scs);
58
+
59
+ return;
60
+ }
61
+
62
+
63
+ /* Polynomial evaluation of cos(x) over [-Pi/4, +Pi/4]
64
+ Approximation error lower than 2^(-128) */
65
+
66
+ static void scs_cos(scs_ptr x){
67
+ scs_t res_scs;
68
+ scs_t x2;
69
+ int i;
70
+
71
+ scs_square(x2, x);
72
+ scs_mul(res_scs, cos_scs_poly_ptr[0], x2);
73
+ for(i=1; i<DEGREE_COS_SCS/2; i++){
74
+ scs_add(res_scs, cos_scs_poly_ptr[i], res_scs);
75
+ scs_mul(res_scs, res_scs, x2);
76
+ }
77
+ /* The last coefficient is exactly one and is not read from the file */
78
+ scs_add(x, res_scs, SCS_ONE);
79
+
80
+ return ;
81
+ }
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+ double scs_sin_rn(double x){
91
+ scs_t sc1, sc2;
92
+ double resd;
93
+ int N;
94
+
95
+
96
+ #if EVAL_PERF
97
+ crlibm_second_step_taken++;
98
+ #endif
99
+
100
+ scs_set_d(sc1, x);
101
+ N = rem_pio2_scs(sc2, sc1);
102
+ N = N & 0x0000003; /* extract the 2 last bits of N */
103
+ switch (N){
104
+ case 0:
105
+ scs_sin(sc2);
106
+ scs_get_d(&resd, sc2);
107
+ return resd;
108
+ case 1:
109
+ scs_cos(sc2);
110
+ scs_get_d(&resd, sc2);
111
+ return resd;
112
+ case 2:
113
+ scs_sin(sc2);
114
+ scs_get_d(&resd, sc2);
115
+ return -resd;
116
+ case 3:
117
+ scs_cos(sc2);
118
+ scs_get_d(&resd, sc2);
119
+ return -resd;
120
+ default:
121
+ fprintf(stderr,"ERREUR: %d is not a valid value in s_scs_sin \n", N);
122
+ return 0.0;
123
+ }
124
+ }
125
+
126
+
127
+
128
+
129
+ double scs_sin_rd(double x){
130
+ scs_t sc1, sc2;
131
+ double resd;
132
+ int N;
133
+
134
+ #if EVAL_PERF
135
+ crlibm_second_step_taken++;
136
+ #endif
137
+
138
+ scs_set_d(sc1, x);
139
+ N = rem_pio2_scs(sc2, sc1);
140
+ N = N & 0x0000003; /* extract the 2 last bits of N */
141
+ switch (N){
142
+ case 0:
143
+ scs_sin(sc2);
144
+ scs_get_d_minf(&resd, sc2);
145
+ return resd;
146
+ case 1:
147
+ scs_cos(sc2);
148
+ scs_get_d_minf(&resd, sc2);
149
+ return resd;
150
+ case 2:
151
+ scs_sin(sc2);
152
+ scs_get_d_pinf(&resd, sc2);
153
+ return -resd;
154
+ case 3:
155
+ scs_cos(sc2);
156
+ scs_get_d_pinf(&resd, sc2);
157
+ return -resd;
158
+ default:
159
+ fprintf(stderr,"ERREUR: %d is not a valid value in s_scs_sin \n", N);
160
+ exit(1);
161
+ }
162
+ return resd;
163
+ }
164
+
165
+
166
+
167
+
168
+ double scs_sin_ru(double x){
169
+ scs_t sc1, sc2;
170
+ double resd;
171
+ int N;
172
+
173
+ #if EVAL_PERF
174
+ crlibm_second_step_taken++;
175
+ #endif
176
+
177
+ scs_set_d(sc1, x);
178
+ N = rem_pio2_scs(sc2, sc1);
179
+ N = N & 0x0000003; /* extract the 2 last bits of N */
180
+ switch (N){
181
+ case 0:
182
+ scs_sin(sc2);
183
+ scs_get_d_pinf(&resd, sc2);
184
+ return resd;
185
+ case 1:
186
+ scs_cos(sc2);
187
+ scs_get_d_pinf(&resd, sc2);
188
+ return resd;
189
+ case 2:
190
+ scs_sin(sc2);
191
+ scs_get_d_minf(&resd, sc2);
192
+ return -resd;
193
+ case 3:
194
+ scs_cos(sc2);
195
+ scs_get_d_minf(&resd, sc2);
196
+ return -resd;
197
+ default:
198
+ fprintf(stderr,"ERREUR: %d is not a valid value in s_scs_sin \n", N);
199
+ exit(1);
200
+ }
201
+ return resd;
202
+ }
203
+
204
+
205
+
206
+
207
+ double scs_sin_rz(double x){
208
+ scs_t sc1, sc2;
209
+ double resd;
210
+ int N;
211
+
212
+ #if EVAL_PERF
213
+ crlibm_second_step_taken++;
214
+ #endif
215
+
216
+ scs_set_d(sc1, x);
217
+ N = rem_pio2_scs(sc2, sc1);
218
+ N = N & 0x0000003; /* extract the 2 last bits of N */
219
+ switch (N){
220
+ case 0:
221
+ scs_sin(sc2);
222
+ scs_get_d_zero(&resd, sc2);
223
+ return resd;
224
+ case 1:
225
+ scs_cos(sc2);
226
+ scs_get_d_zero(&resd, sc2);
227
+ return resd;
228
+ case 2:
229
+ scs_sin(sc2);
230
+ scs_get_d_zero(&resd, sc2);
231
+ return -resd;
232
+ case 3:
233
+ scs_cos(sc2);
234
+ scs_get_d_zero(&resd, sc2);
235
+ return -resd;
236
+ default:
237
+ fprintf(stderr,"ERREUR: %d is not a valid value in s_scs_sin \n", N);
238
+ exit(1);
239
+ }
240
+ return resd;
241
+ }
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+ double scs_cos_rn(double x){
250
+ scs_t sc1, sc2;
251
+ double resd;
252
+ int N;
253
+
254
+ #if EVAL_PERF
255
+ crlibm_second_step_taken++;
256
+ #endif
257
+
258
+ scs_set_d(sc1, x);
259
+ N = rem_pio2_scs(sc2, sc1);
260
+ N = N & 0x0000003; /* extract the 2 last bits of N */
261
+ switch (N){
262
+ case 0:
263
+ scs_cos(sc2);
264
+ scs_get_d(&resd, sc2);
265
+ return resd;
266
+ case 1:
267
+ scs_sin(sc2);
268
+ scs_get_d(&resd, sc2);
269
+ return -resd;
270
+ case 2:
271
+ scs_cos(sc2);
272
+ scs_get_d(&resd, sc2);
273
+ return -resd;
274
+ case 3:
275
+ scs_sin(sc2);
276
+ scs_get_d(&resd, sc2);
277
+ return resd;
278
+ default:
279
+ fprintf(stderr,"ERREUR: %d is not a valid value in s_cos \n", N);
280
+ return 0.0;
281
+ }
282
+
283
+ }
284
+
285
+
286
+ double scs_cos_rd(double x){
287
+ scs_t sc1, sc2;
288
+ double resd;
289
+ int N;
290
+
291
+ #if EVAL_PERF
292
+ crlibm_second_step_taken++;
293
+ #endif
294
+
295
+ scs_set_d(sc1, x);
296
+ N = rem_pio2_scs(sc2, sc1);
297
+ N = N & 0x0000003; /* extract the 2 last bits of N */
298
+ switch (N){
299
+ case 0:
300
+ scs_cos(sc2);
301
+ scs_get_d_minf(&resd, sc2);
302
+ return resd;
303
+ case 1:
304
+ scs_sin(sc2);
305
+ scs_get_d_pinf(&resd, sc2);
306
+ return -resd;
307
+ case 2:
308
+ scs_cos(sc2);
309
+ scs_get_d_pinf(&resd, sc2);
310
+ return -resd;
311
+ case 3:
312
+ scs_sin(sc2);
313
+ scs_get_d_minf(&resd, sc2);
314
+ return resd;
315
+ default:
316
+ fprintf(stderr,"ERREUR: %d is not a valid value in s_cos \n", N);
317
+ exit(1);
318
+ }
319
+ return resd;
320
+ }
321
+
322
+
323
+ double scs_cos_ru(double x){
324
+ scs_t sc1, sc2;
325
+ double resd;
326
+ int N;
327
+
328
+ #if EVAL_PERF
329
+ crlibm_second_step_taken++;
330
+ #endif
331
+
332
+ scs_set_d(sc1, x);
333
+ N = rem_pio2_scs(sc2, sc1);
334
+ N = N & 0x0000003; /* extract the 2 last bits of N */
335
+ switch (N){
336
+ case 0:
337
+ scs_cos(sc2);
338
+ scs_get_d_pinf(&resd, sc2);
339
+ return resd;
340
+ case 1:
341
+ scs_sin(sc2);
342
+ scs_get_d_minf(&resd, sc2);
343
+ return -resd;
344
+ case 2:
345
+ scs_cos(sc2);
346
+ scs_get_d_minf(&resd, sc2);
347
+ return -resd;
348
+ case 3:
349
+ scs_sin(sc2);
350
+ scs_get_d_pinf(&resd, sc2);
351
+ return resd;
352
+ default:
353
+ fprintf(stderr,"ERREUR: %d is not a valid value in s_cos \n", N);
354
+ exit(1);
355
+ }
356
+ return resd;
357
+ }
358
+
359
+
360
+
361
+ double scs_cos_rz(double x){
362
+ scs_t sc1, sc2;
363
+ double resd;
364
+ int N;
365
+
366
+ #if EVAL_PERF
367
+ crlibm_second_step_taken++;
368
+ #endif
369
+
370
+ scs_set_d(sc1, x);
371
+ N = rem_pio2_scs(sc2, sc1);
372
+ N = N & 0x0000003; /* extract the 2 last bits of N */
373
+ switch (N){
374
+ case 0:
375
+ scs_cos(sc2);
376
+ scs_get_d_zero(&resd, sc2);
377
+ return resd;
378
+ case 1:
379
+ scs_sin(sc2);
380
+ scs_get_d_zero(&resd, sc2);
381
+ return -resd;
382
+ case 2:
383
+ scs_cos(sc2);
384
+ scs_get_d_zero(&resd, sc2);
385
+ return -resd;
386
+ case 3:
387
+ scs_sin(sc2);
388
+ scs_get_d_zero(&resd, sc2);
389
+ return resd;
390
+ default:
391
+ fprintf(stderr,"ERREUR: %d is not a valid value in s_cos \n", N);
392
+ exit(1);
393
+ }
394
+ return resd;
395
+ }
396
+
397
+
398
+
399
+
400
+
401
+ /*************************************************************
402
+ * Tangent *
403
+ *************************************************************/
404
+
405
+
406
+ /* The main function */
407
+
408
+ static void scs_tan(double x, scs_ptr res_scs){
409
+ scs_t x_scs;
410
+ scs_t x2;
411
+ int i;
412
+ scs_t y_scs;
413
+ int N;
414
+
415
+ scs_set_d(x_scs, x);
416
+
417
+
418
+ N = rem_pio2_scs(y_scs, x_scs); /* x (=sc2) is in [-Pi/4,Pi/4] */
419
+ N = N & 1; /* extract the last bit of N */
420
+ scs_square(x2, y_scs);
421
+
422
+ scs_mul(res_scs, tan_scs_poly_ptr[0], x2);
423
+
424
+ for(i=1; i<(DEGREE_TAN_SCS-1)/2; i++){ /* The last coeff is not read from the file. */
425
+ scs_add(res_scs, tan_scs_poly_ptr[i], res_scs);
426
+ scs_mul(res_scs, res_scs, x2);
427
+ }
428
+
429
+ scs_mul(res_scs, res_scs, y_scs);
430
+ scs_add(res_scs, y_scs, res_scs);
431
+
432
+ if(N==1) {
433
+ scs_inv(res_scs, res_scs);
434
+ res_scs->sign = -res_scs->sign;
435
+ }
436
+ }
437
+
438
+
439
+
440
+
441
+
442
+ double scs_tan_rn(double x){
443
+ scs_t res_scs;
444
+ double resd;
445
+
446
+ #if EVAL_PERF
447
+ crlibm_second_step_taken++;
448
+ #endif
449
+
450
+ scs_tan(x,res_scs);
451
+ scs_get_d(&resd, res_scs);
452
+ return resd;
453
+ }
454
+
455
+
456
+
457
+ double scs_tan_rd(double x){
458
+ scs_t res_scs;
459
+ double resd;
460
+
461
+ #if EVAL_PERF
462
+ crlibm_second_step_taken++;
463
+ #endif
464
+
465
+ scs_tan(x,res_scs);
466
+ scs_get_d_minf(&resd, res_scs);
467
+ return resd;
468
+ }
469
+
470
+
471
+
472
+ double scs_tan_ru(double x){
473
+ scs_t res_scs;
474
+ double resd;
475
+
476
+ #if EVAL_PERF
477
+ crlibm_second_step_taken++;
478
+ #endif
479
+
480
+ scs_tan(x,res_scs);
481
+ scs_get_d_pinf(&resd, res_scs);
482
+ return resd;
483
+ }
484
+
485
+
486
+
487
+ double scs_tan_rz(double x){
488
+ scs_t res_scs;
489
+ double resd;
490
+
491
+ #if EVAL_PERF
492
+ crlibm_second_step_taken++;
493
+ #endif
494
+
495
+ scs_tan(x,res_scs);
496
+ scs_get_d_zero(&resd, res_scs);
497
+ return resd;
498
+ }
499
+
500
+