crmf 0.1.1 → 0.1.2

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 +102 -1
  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 +16 -16
  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 +104 -3
  111. data/ext/crlibm-1.0beta4.tar.gz +0 -0
@@ -0,0 +1,125 @@
1
+ #include <stdio.h>
2
+
3
+ #include <gmp.h>
4
+ #include <mpfr.h>
5
+
6
+
7
+ /*
8
+ * This program builds the tables used in the first step of the exponential
9
+ * Auteur : David Defour in a hurry Date : 15/06/2003
10
+ *
11
+ * build command:
12
+ gcc -I/usr/local/include/ -L/usr/local/lib/ exp_firststep_table.c -o exp_firststep_table -lgmp -lmpfr
13
+ */
14
+
15
+
16
+ /* don't forget to check that */
17
+ #define LITTLE_ENDIAN
18
+
19
+ #ifdef LITTLE_ENDIAN
20
+ #define HI(x) *(1+(int*)&x)
21
+ #define LO(x) *(int*)&x
22
+ #else
23
+ #define HI(x) *(int*)&x
24
+ #define LO(x) *(1+(int*)&x)
25
+ #endif
26
+
27
+
28
+ /* This is the number of bits considered to address the table. It can
29
+ be changed by the command-line second argument, but should stay to
30
+ 8 for the exp as distributed */
31
+
32
+ int PREC=8;
33
+
34
+
35
+
36
+ #define CC_MPFR(d1, d2, a, res, rest, f, A, B){ \
37
+ mpfr_exp(res, a, GMP_RNDN); \
38
+ d1 = mpfr_get_d(res, GMP_RNDN);\
39
+ mpfr_set_d(rest, d1, GMP_RNDN);\
40
+ mpfr_sub(res, res, rest, GMP_RNDN);\
41
+ d2 = mpfr_get_d(res, GMP_RNDN); \
42
+ fprintf(f,"\t {{{0x%.8x, 0x%.8x}}, {{0x%.8x, 0x%.8x}}}", A(d1), B(d1), A(d2), B(d2));}
43
+
44
+
45
+ void compute(FILE *f){
46
+ mpfr_t a, b, step, res, rest;
47
+ double d, d1, d2;
48
+ int i, end;
49
+
50
+ /* Memory allocation */
51
+ mpfr_init2(a, 300);
52
+ mpfr_init2(b, 300);
53
+ mpfr_init2(res, 300);
54
+ mpfr_init2(rest,300);
55
+ mpfr_init2(step,300);
56
+
57
+
58
+ /* Set step to 2^-PREC */
59
+ mpfr_set_ui(step, 1, GMP_RNDN);
60
+ mpfr_div_2ui(step, step, PREC, GMP_RNDN);
61
+
62
+ /* Compute bound of the interval [a, b] */
63
+ mpfr_set_ui(res, 2, GMP_RNDN);
64
+ mpfr_log(a, res, GMP_RNDN);
65
+ mpfr_div_2ui(a, a, 1, GMP_RNDN);
66
+
67
+ mpfr_mul_2ui(a, a, PREC, GMP_RNDN);
68
+ mpfr_round(a, a);
69
+ d = mpfr_get_d(a, GMP_RNDN);
70
+ mpfr_div_2ui(a, a, PREC, GMP_RNDN);
71
+
72
+ mpfr_neg(a, a, GMP_RNDN);
73
+ mpfr_set(b, a, GMP_RNDN);
74
+
75
+ end = (2 * d) + 1; /* +1 because this range is centered in 0 and '0' need to be taken into account */
76
+
77
+ fprintf(f,"static const scs_db_number tab_exp[%d][2] = { \n",end);
78
+ fprintf(f,"#ifdef WORDS_BIGENDIAN\n");
79
+
80
+ for(i=0; i<(end-1) ; i++){
81
+ CC_MPFR(d1, d2, a, res, rest, f, HI, LO);
82
+ fprintf(f,", \n");
83
+ mpfr_add(a, a, step, GMP_RNDN);
84
+ }
85
+ CC_MPFR(d1, d2, a, res, rest, f, HI, LO);
86
+
87
+ fprintf(f,"\n#else \n");
88
+ mpfr_set(a, b, GMP_RNDN);
89
+ for(i=0; i<(end-1) ; i++){
90
+ CC_MPFR(d1, d2, a, res, rest, f, LO, HI);
91
+ fprintf(f,", \n");
92
+ mpfr_add(a, a, step, GMP_RNDN);
93
+ }
94
+ CC_MPFR(d1, d2, a, res, rest, f, LO, HI);
95
+
96
+ fprintf(f,"\n#endif \n}; \n\n");
97
+
98
+
99
+ mpfr_clear(a);
100
+ mpfr_clear(b);
101
+ mpfr_clear(res);
102
+ mpfr_clear(rest);
103
+ mpfr_clear(step);
104
+ }
105
+
106
+
107
+
108
+ int main (int argc, char *argv[])
109
+ {
110
+ FILE *f;
111
+
112
+ if (argc == 3)
113
+ PREC = atoi(argv[2]);
114
+
115
+ f = fopen (argv[1], "w");
116
+ if (f== NULL){
117
+ fprintf(stderr," Cannot open file %s \n", argv[1]); exit(1);
118
+ }
119
+
120
+ compute(f);
121
+
122
+ fclose(f);
123
+ return 0;
124
+ }
125
+
@@ -0,0 +1,119 @@
1
+ #include "crlibm.h"
2
+ #include "crlibm_private.h"
3
+ #include "triple-double.h"
4
+ #include "expm1.h"
5
+
6
+ #define AVOID_FMA 0
7
+
8
+
9
+ extern void expm1_direct_td(double *expm1h, double *expm1m, double *expm1l,
10
+ double x, double xSqHalfh, double xSqHalfl, double xSqh, double xSql, int expoX);
11
+
12
+ extern void expm1_common_td(double *expm1h, double *expm1m, double *expm1l,
13
+ double rh, double rm, double rl,
14
+ double tbl1h, double tbl1m, double tbl1l,
15
+ double tbl2h, double tbl2m, double tbl2l,
16
+ int M);
17
+
18
+
19
+ /* Function expm1_13
20
+
21
+ Computes exp(x)-1 with an accuracy of 120 bits (128 for |x| <= 2^(-5)) as
22
+
23
+ (expm1h + expm1m + expm1l) \approx exp(x) - 1
24
+
25
+ There is no special case handling.
26
+
27
+ |x| is supposed to be greater than 2^(-53)
28
+
29
+ x is supposed to be in the range -37...709
30
+
31
+ The triple-double exph + expm + expl is non-overlapping.
32
+
33
+ */
34
+
35
+ void expm1_13(double *expm1h, double *expm1m, double *expm1l, double x) {
36
+ db_number xdb, shiftedXMultdb;
37
+ int xIntHi, expoX, k, M, index1, index2;
38
+ double xSqh, xSql, xSqHalfh, xSqHalfl;
39
+ double t1, t2;
40
+ double msLog2Div2LMultKh, msLog2Div2LMultKm, msLog2Div2LMultKl;
41
+ double xMultLog2InvMult2L, shiftedXMult, kd, rh, rm, rl;
42
+ double tbl1h, tbl1m, tbl1l, tbl2h, tbl2m, tbl2l;
43
+
44
+
45
+ xdb.d = x;
46
+ xIntHi = xdb.i[HI] & 0x7fffffff;
47
+
48
+ /* Test if we have |x| <= 1/4-1/2ulp(1/4) for knowing if we use exp(x) or approximate directly */
49
+
50
+ if (xIntHi < DIRECTINTERVALBOUND) {
51
+ /* We approximate expm1 directly after a range reduction as follows
52
+
53
+ expm1(x) = (expm1(x/2) + 2) * expm1(x/2)
54
+
55
+ We perform the range reduction in such a way that finally |x| < 1/32
56
+ */
57
+
58
+ /* Extract the exponent of |x| and add 5 (2^5 = 32) */
59
+ expoX = ((xIntHi & 0x7ff00000) >> 20) - (1023 - 5);
60
+
61
+ /* If this particularily biased exponent expoX is negative, we are already less than 1/32 */
62
+ if (expoX >= 0) {
63
+ /* If we are here, we must perform range reduction */
64
+
65
+
66
+ /* We multiply x by 2^(-expoX-1) by bit manipulation
67
+ x cannot be denormalized so there is no danger
68
+ */
69
+ xdb.i[HI] += (-expoX-1) << 20;
70
+
71
+ /* We reassign the new x and maintain xIntHi */
72
+
73
+ xIntHi = xdb.i[HI] & 0x7fffffff;
74
+ x = xdb.d;
75
+ }
76
+
77
+ /* Here, we have always |x| < 1/32 */
78
+
79
+
80
+ /* Double precision evaluation steps and one double-double step */
81
+
82
+ Mul12(&xSqh,&xSql,x,x);
83
+ xSqHalfh = 0.5 * xSqh;
84
+ xSqHalfl = 0.5 * xSql;
85
+
86
+ expm1_direct_td(expm1h, expm1m, expm1l, x, xSqHalfh, xSqHalfl, xSqh, xSql, expoX);
87
+
88
+ } else {
89
+
90
+ /* If we are here, we can use expm1(x) = exp(x) - 1 */
91
+
92
+ /* Range reduction - exact part: compute k as double and as int */
93
+
94
+ xMultLog2InvMult2L = x * log2InvMult2L;
95
+ shiftedXMult = xMultLog2InvMult2L + shiftConst;
96
+ kd = shiftedXMult - shiftConst;
97
+ shiftedXMultdb.d = shiftedXMult;
98
+ k = shiftedXMultdb.i[LO];
99
+ M = k >> 12;
100
+ index1 = k & INDEXMASK1;
101
+ index2 = (k & INDEXMASK2) >> 6;
102
+
103
+
104
+ Mul133(&msLog2Div2LMultKh,&msLog2Div2LMultKm,&msLog2Div2LMultKl,kd,msLog2Div2Lh,msLog2Div2Lm,msLog2Div2Ll);
105
+ t1 = x + msLog2Div2LMultKh;
106
+ Add12Cond(rh,t2,t1,msLog2Div2LMultKm);
107
+ Add12Cond(rm,rl,t2,msLog2Div2LMultKl);
108
+
109
+ tbl1h = twoPowerIndex1[index1].hi;
110
+ tbl1m = twoPowerIndex1[index1].mi;
111
+ tbl2h = twoPowerIndex2[index2].hi;
112
+ tbl2m = twoPowerIndex2[index2].mi;
113
+ tbl1l = twoPowerIndex1[index1].lo;
114
+ tbl2l = twoPowerIndex2[index2].lo;
115
+
116
+ expm1_common_td(expm1h, expm1m, expm1l, rh, rm, rl, tbl1h, tbl1m, tbl1l, tbl2h, tbl2m, tbl2l, M);
117
+
118
+ }
119
+ }