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,261 @@
1
+ #include "crlibm.h"
2
+ #include "crlibm_private.h"
3
+ /*
4
+ * Constant to compute the natural logarithm.
5
+ */
6
+
7
+ #ifdef WORDS_BIGENDIAN
8
+ static const db_number
9
+ norm_number = {{0x3FD60000, 0x00000000}}; /* 11*2^(-5) */
10
+ #else
11
+ static const db_number
12
+ norm_number = {{0x00000000, 0x3FD60000}}; /* 11*2^(-5) */
13
+ #endif
14
+
15
+ #define SQRT_2 1.4142135623730950489e0
16
+
17
+ static const scs
18
+ sc_ln2={{0x2c5c85fd, 0x3d1cf79a, 0x2f278ece, 0x1803f2f6,
19
+ 0x2bd03cd0, 0x3267298b, 0x18b62834, 0x175b8baa},
20
+ DB_ONE, -1, 1 };
21
+ #define sc_ln2_ptr (scs_ptr)(&sc_ln2)
22
+
23
+
24
+ static const scs table_ti[13]=
25
+ /* ~-3.746934e-01 */
26
+ {{{0x17fafa3b, 0x360546fb, 0x1e6fdb53, 0x0b1225e6,
27
+ 0x15f38987, 0x26664702, 0x3cb1bf6d, 0x118a64f9},
28
+ DB_ONE, -1, -1 }
29
+ ,
30
+ /* ~-2.876821e-01 */
31
+ {{0x12696211, 0x0d36e49e, 0x03beb767, 0x1b02aa70,
32
+ 0x2a30f490, 0x3732bb37, 0x2425c6da, 0x1fc53d0e},
33
+ DB_ONE, -1, -1 }
34
+ ,
35
+ /* ~-2.076394e-01 */
36
+ {{0x0d49f69e, 0x115b3c6d, 0x395f53bd, 0x0b901b99,
37
+ 0x2e77188a, 0x3e3d1ab5, 0x1147dede, 0x05483ae4},
38
+ DB_ONE, -1, -1 }
39
+ ,
40
+ /* ~-1.335314e-01 */
41
+ {{0x088bc741, 0x04fc8f7b, 0x319c5a0f, 0x38e5bd03,
42
+ 0x31dda8fe, 0x30f08645, 0x2fa1d5c5, 0x02c6529d},
43
+ DB_ONE, -1, -1 }
44
+ ,
45
+ /* ~-6.453852e-02 */
46
+ {{0x0421662d, 0x19e3a068, 0x228ff66f, 0x3503372c,
47
+ 0x04bf1b16, 0x0ff1b85c, 0x006c21b2, 0x21a9efd6},
48
+ DB_ONE, -1, -1 }
49
+ ,
50
+ /* ZERO */
51
+ {{0x00000000, 0x00000000, 0x00000000, 0x00000000,
52
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000},
53
+ {{0, 0}}, 0, 1 }
54
+ ,
55
+ /* ~6.062462e-02 */
56
+ {{0x03e14618, 0x008b1533, 0x02f992e2, 0x37759978,
57
+ 0x2634d1d3, 0x13375edb, 0x2e4634ea, 0x1dcf0aef},
58
+ DB_ONE, -1, 1 }
59
+ ,
60
+ /* ~1.177830e-01 */
61
+ {{0x0789c1db, 0x22af2e5e, 0x27aa1fff, 0x21fe9e15,
62
+ 0x176e53af, 0x04015c6b, 0x021a0541, 0x006df1d7},
63
+ DB_ONE, -1, 1 }
64
+ ,
65
+ /* ~1.718503e-01 */
66
+ {{0x0aff9838, 0x14f27a79, 0x039f1050, 0x0e424775,
67
+ 0x3f35571c, 0x355ff008, 0x1ca13efc, 0x3c2c8490},
68
+ DB_ONE, -1, 1 }
69
+ ,
70
+ /* ~2.231436e-01 */
71
+ {{0x0e47fbe3, 0x33534435, 0x212ec0f7, 0x25ff7344,
72
+ 0x2571d97a, 0x274129e2, 0x12b111db, 0x2c051568},
73
+ DB_ONE, -1, 1 }
74
+ ,
75
+ /* ~2.719337e-01 */
76
+ {{0x11675cab, 0x2ae98380, 0x39cc7d57, 0x041b8b82,
77
+ 0x0fc19f41, 0x0a43c91d, 0x1523ef69, 0x164b69f6},
78
+ DB_ONE, -1, 1 }
79
+ ,
80
+ /* ~3.184537e-01 */
81
+ {{0x14618bc2, 0x0717b09f, 0x10b7b37b, 0x0cf1cd10,
82
+ 0x15dcb349, 0x0c00c397, 0x2c39cc9b, 0x274c94a8},
83
+ DB_ONE, -1, 1 }
84
+ ,
85
+ {{0x1739d7f6, 0x2ef401a7, 0x0e24c53f, 0x2b4fbde5,
86
+ 0x2ab77843, 0x1cea5975, 0x1eeef249, 0x384d2344},
87
+ DB_ONE, -1, 1 }
88
+ };
89
+ #define table_ti_ptr (scs_ptr)&table_ti
90
+
91
+ static const scs table_inv_wi[13]=
92
+ /* ~1.454545e+00 */
93
+ {{{0x00000001, 0x1d1745d1, 0x1d1745d1, 0x1d1745d1,
94
+ 0x1d1745d1, 0x1d1745d1, 0x1d183e2a, 0x36835582},
95
+ DB_ONE, 0, 1 }
96
+ ,
97
+ /* ~1.333333e+00 */
98
+ {{0x00000001, 0x15555555, 0x15555555, 0x15555555,
99
+ 0x15555555, 0x15555555, 0x15549b7e, 0x1a416c6b},
100
+ DB_ONE, 0, 1 }
101
+ ,
102
+ /* ~1.230769e+00 */
103
+ {{0x00000001, 0x0ec4ec4e, 0x313b13b1, 0x0ec4ec4e,
104
+ 0x313b13b1, 0x0ec4ec4e, 0x313a6825, 0x3ab28b77},
105
+ DB_ONE, 0, 1 }
106
+ ,
107
+ /* ~1.142857e+00 */
108
+ {{0x00000001, 0x09249249, 0x09249249, 0x09249249,
109
+ 0x09249249, 0x09249249, 0x09238b74, 0x26f620a6},
110
+ DB_ONE, 0, 1 }
111
+ ,
112
+ /* ~1.066667e+00 */
113
+ {{0x00000001, 0x04444444, 0x11111111, 0x04444444,
114
+ 0x11111111, 0x04444444, 0x1111d60e, 0x1f0c9d58},
115
+ DB_ONE, 0, 1 }
116
+ ,
117
+ /* ~1.000000e+00 */
118
+ {{0x00000001, 0x00000000, 0x00000000, 0x00000000,
119
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000},
120
+ DB_ONE, 0, 1 }
121
+ ,
122
+ /* ~9.411765e-01 */
123
+ {{0x3c3c3c3c, 0x0f0f0f0f, 0x03c3c3c3, 0x30f0f0f0,
124
+ 0x3c3c3c3c, 0x0f0f923d, 0x16e0e0a4, 0x3a84202f},
125
+ DB_ONE, -1, 1 }
126
+ ,
127
+ /* ~8.888889e-01 */
128
+ {{0x38e38e38, 0x38e38e38, 0x38e38e38, 0x38e38e38,
129
+ 0x38e38e38, 0x38e3946a, 0x2e0ee2c9, 0x0d6e0fbd},
130
+ DB_ONE, -1, 1 }
131
+ ,
132
+ /* ~8.421053e-01 */
133
+ {{0x35e50d79, 0x10d79435, 0x39435e50, 0x35e50d79,
134
+ 0x10d79435, 0x3943324d, 0x0637ea85, 0x131a67ba},
135
+ DB_ONE, -1, 1 }
136
+ ,
137
+ /* ~8.000000e-01 */
138
+ {{0x33333333, 0x0ccccccc, 0x33333333, 0x0ccccccc,
139
+ 0x33333333, 0x0ccccccc, 0x33333333, 0x0ccccccc},
140
+ DB_ONE, -1, 1 }
141
+ ,
142
+ /* ~7.619048e-01 */
143
+ {{0x30c30c30, 0x30c30c30, 0x30c30c30, 0x30c30c30,
144
+ 0x30c30c30, 0x30c2f1a4, 0x160958a1, 0x2b03bc88},
145
+ DB_ONE, -1, 1 }
146
+ ,
147
+ /* ~7.272727e-01 */
148
+ {{0x2e8ba2e8, 0x2e8ba2e8, 0x2e8ba2e8, 0x2e8ba2e8,
149
+ 0x2e8ba2e8, 0x2e8bcb74, 0x2d78b525, 0x00a1db67},
150
+ DB_ONE, -1, 1 }
151
+ ,
152
+ /* ~6.956522e-01 */
153
+ {{0x2c8590b2, 0x0590b216, 0x10b21642, 0x321642c8,
154
+ 0x1642c859, 0x02c8590b, 0x08590b21, 0x190b2164},
155
+ DB_ONE, -1, 1 }
156
+ };
157
+ #define table_inv_wi_ptr (scs_ptr)&table_inv_wi
158
+
159
+
160
+ static const scs constant_poly[20]=
161
+ /*0 ~-5.023367e-02 */
162
+ {{{0x0337074b, 0x275aac5c, 0x2cf4a893, 0x38013cc3,
163
+ 0x149a3416, 0x0e067307, 0x12745608, 0x1658e0d5},
164
+ DB_ONE, -1, -1 }
165
+ ,
166
+ /*1 ~5.286469e-02 */
167
+ {{0x03622298, 0x252ff65c, 0x03001550, 0x2f457908,
168
+ 0x32f78ecc, 0x17442a4e, 0x1d806366, 0x2c50350e},
169
+ DB_ONE, -1, 1 }
170
+ ,
171
+ /*2 ~-5.555504e-02 */
172
+ {{0x038e36bb, 0x30665a9c, 0x119434c7, 0x3fdec8cb,
173
+ 0x37dd3adb, 0x2663cd45, 0x230e43e9, 0x32b9663c},
174
+ DB_ONE, -1, -1 }
175
+ ,
176
+ /*3 ~5.882305e-02 */
177
+ {{0x03c3c1bb, 0x38c473ae, 0x192b9c18, 0x242b7c4e,
178
+ 0x3da8edc8, 0x04454ffe, 0x2cf133c6, 0x0c926fd0},
179
+ DB_ONE, -1, 1 }
180
+ ,
181
+ /*4 ~-6.250000e-02 */
182
+ {{0x04000000, 0x2b72bb0a, 0x038f5efc, 0x34665092,
183
+ 0x2461b6c9, 0x172f7050, 0x1218b5c1, 0x104862d7},
184
+ DB_ONE, -1, -1 }
185
+ ,
186
+ /*5 ~6.666667e-02 */
187
+ {{0x04444444, 0x374f3324, 0x1531bcf1, 0x1d7d23fc,
188
+ 0x26ff9670, 0x38fc33ae, 0x15bf1cfb, 0x2c9f1c2d},
189
+ DB_ONE, -1, 1 }
190
+ ,
191
+ /*6 ~-7.142857e-02 */
192
+ {{0x04924924, 0x2489e5b6, 0x288b19c5, 0x2893519b,
193
+ 0x2c3f35c0, 0x0b8bfdce, 0x3541ab49, 0x1de415bc},
194
+ DB_ONE, -1, -1 }
195
+ ,
196
+ /*7 ~7.692308e-02 */
197
+ {{0x04ec4ec4, 0x3b0ce4bd, 0x14d14046, 0x0243ade9,
198
+ 0x083cc34f, 0x393e6a5a, 0x2c1855f2, 0x259d599f},
199
+ DB_ONE, -1, 1 }
200
+ ,
201
+ /*8 ~-8.333333e-02 */
202
+ {{0x05555555, 0x1555565b, 0x064b42af, 0x13bc7961,
203
+ 0x1396754b, 0x33d85415, 0x2ba548d4, 0x039c4ff6},
204
+ DB_ONE, -1, -1 }
205
+ ,
206
+ /*9 ~9.090909e-02 */
207
+ {{0x05d1745d, 0x05d1751c, 0x24facd05, 0x07540f86,
208
+ 0x014f2ec1, 0x3bb3fa8b, 0x02e1da4c, 0x3304817c},
209
+ DB_ONE, -1, 1 }
210
+ ,
211
+ /*10 ~-1.000000e-01 */
212
+ {{0x06666666, 0x19999999, 0x21667ee1, 0x0f5f75ea,
213
+ 0x353af37f, 0x2578daa1, 0x07c76f47, 0x16541534},
214
+ DB_ONE, -1, -1 }
215
+ ,
216
+ /*11 ~1.111111e-01 */
217
+ {{0x071c71c7, 0x071c71c7, 0x03e7af88, 0x2fca5d74,
218
+ 0x0bb43f38, 0x050edb70, 0x3631b696, 0x1fc3e0d3},
219
+ DB_ONE, -1, 1 }
220
+ ,
221
+ /*12 ~-1.250000e-01 */
222
+ {{0x08000000, 0x00000000, 0x00003ac6, 0x36c11384,
223
+ 0x2d596ab4, 0x09257878, 0x0597dc26, 0x2d60813a},
224
+ DB_ONE, -1, -1 }
225
+ ,
226
+ /*13 ~1.428571e-01 */
227
+ {{0x09249249, 0x09249249, 0x0924b1db, 0x0d002ac1,
228
+ 0x0eafd708, 0x2b4df21d, 0x0458da93, 0x2d11460c},
229
+ DB_ONE, -1, 1 }
230
+ ,
231
+ /*14 ~-1.666667e-01 */
232
+ {{0x0aaaaaaa, 0x2aaaaaaa, 0x2aaaaaa9, 0x0bb6630e,
233
+ 0x2e44a5cf, 0x39f32e04, 0x105732b9, 0x01a76208},
234
+ DB_ONE, -1, -1 }
235
+ ,
236
+ /*15 ~2.000000e-01 */
237
+ {{0x0ccccccc, 0x33333333, 0x0ccccccc, 0x0bbbe6e8,
238
+ 0x253269ea, 0x0ec2a630, 0x10defc5c, 0x238aef3b},
239
+ DB_ONE, -1, 1 }
240
+ ,
241
+ /*16 ~-2.500000e-01 */
242
+ {{0x10000000, 0x00000000, 0x00000000, 0x0001195c,
243
+ 0x3654cd5a, 0x16ca3471, 0x343d2da0, 0x235273f2},
244
+ DB_ONE, -1, -1 }
245
+ ,
246
+ /*17 ~3.333333e-01 */
247
+ {{0x15555555, 0x15555555, 0x15555555, 0x1555a1e0,
248
+ 0x2eb2094a, 0x07dde891, 0x230e2bfa, 0x28aae6ab},
249
+ DB_ONE, -1, 1 }
250
+ ,
251
+ /*18 ~-5.000000e-01 */
252
+ {{0x1fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff,
253
+ 0x029bd81b, 0x360f63df, 0x28d28bd3, 0x3c15f394},
254
+ DB_ONE, -1, -1 }
255
+ ,
256
+ /*19 ~1.000000e+00 */
257
+ {{0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff,
258
+ 0x39e04b7e, 0x08e4e337, 0x1a1e2ed3, 0x23e85705},
259
+ DB_ONE, -1, 1 }
260
+ };
261
+ #define constant_poly_ptr (scs_ptr)&constant_poly
@@ -0,0 +1,360 @@
1
+ /*
2
+ * Correctly rounded logarithm
3
+ *
4
+ * Author : Daramy Catherine, 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 "crlibm.h"
26
+ #include "crlibm_private.h"
27
+ #include "log_fast.h"
28
+
29
+
30
+ /* switches on various printfs. Default 0 */
31
+ #define DEBUG 0
32
+
33
+
34
+
35
+
36
+ /*
37
+ * 1) First reduction: exponent extraction
38
+ * E
39
+ * x = 2^ .(y) with 1 <= y < 2
40
+ *
41
+ * log(x) = E.log(2) + log(y) where:
42
+ * - log(2) is tabulated
43
+ * - log(y) need to be evaluated
44
+ *
45
+ *
46
+ * 2) Avoiding accuracy problem when E=-1 by testing
47
+ *
48
+ * if (ny >= sqrt(2)) then
49
+ * y = z/2; E = E+1;
50
+ * and,
51
+ * log(x) = (E+1).log(2) + log(y/2)
52
+ *
53
+ * so now: 11/16 <= sqrt(2)/2 <= y < sqrt(2) <= 23/16
54
+ *
55
+ *
56
+ * 3) Second reduction: tabular reduction
57
+ *
58
+ * The interval 1/sqrt(2) .. sqrt(2) is divided in 8 intervals.
59
+ * So, find the interval X_i where y is.
60
+ * And compute z = y - middle(X_i);
61
+ *
62
+ * 4) Computation:
63
+ *
64
+ * Polynomial evaluation of:
65
+ * - P(z) ~ log(z+middle(X_i))
66
+ *
67
+ * -4 -5
68
+ * with |z| < 2^ or 2^ depending the considered interval.
69
+ *
70
+ *
71
+ * 5) Reconstruction:
72
+ * log(x) = E.log(2) + P(z)
73
+ *
74
+ */
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+ /*
83
+ * Function used to evaluate log and pow functions
84
+ */
85
+ void log_quick(double *pres_hi, double *pres_lo, int* prndcstindex, db_number * py, int E) {
86
+ double ln2_times_E_HI, ln2_times_E_LO, res_hi, res_lo;
87
+ double z, res, P_hi, P_lo;
88
+ int k, i;
89
+
90
+ res=(double)E;
91
+ if(E<0) E=-E;
92
+
93
+ /* find the interval including y.d */
94
+ i = ((((*py).i[HI] & 0x001F0000)>>16)-6) ;
95
+ if (i < 10)
96
+ i = i>>1;
97
+ else
98
+ i = ((i-1)>>1);
99
+
100
+ z = (*py).d - (middle[i]).d; /* (exact thanks to Sterbenz Lemma) */
101
+
102
+
103
+ /* Compute ln2_times_E = E*log(2) in double-double */
104
+ Add12( ln2_times_E_HI, ln2_times_E_LO, res*ln2hi.d, res*ln2lo.d);
105
+
106
+ /* Now begin the polynomial evaluation of log(1 + z) */
107
+
108
+ res = (Poly_h[i][DEGREE]).d;
109
+
110
+ for(k=DEGREE-1; k>1; k--){
111
+ res *= z;
112
+ res += (Poly_h[i][k]).d;
113
+ }
114
+
115
+ if(E <= EMIN_FASTPATH) {
116
+ /* Slow path */
117
+ if(E==0) {
118
+ *prndcstindex = 0 ;
119
+ /* In this case we start with a double-double multiplication to get enough relative accuracy */
120
+ Mul12(&P_hi, &P_lo, res, z);
121
+ Add22(&res_hi, &res_lo, (Poly_h[i][1]).d, (Poly_l[i][1]).d, P_hi, P_lo);
122
+ Mul22(&P_hi, &P_lo, res_hi, res_lo, z, 0.);
123
+ Add22(pres_hi, pres_lo, (Poly_h[i][0]).d, (Poly_l[i][0]).d, P_hi, P_lo);
124
+ }
125
+ else
126
+ {
127
+ if(E > EMIN_MEDIUMPATH)
128
+ *prndcstindex = 2;
129
+ else
130
+ *prndcstindex =1;
131
+ P_hi=res*z;
132
+ Add12(res_hi, res_lo, (Poly_h[i][1]).d, (Poly_l[i][1]).d + P_hi);
133
+ Mul22(&P_hi, &P_lo, res_hi, res_lo, z, 0.);
134
+ Add22(&res_hi, &res_lo, (Poly_h[i][0]).d, (Poly_l[i][0]).d, P_hi, P_lo);
135
+
136
+ /* Add E*log(2) */
137
+ Add22(pres_hi, pres_lo, ln2_times_E_HI, ln2_times_E_LO, res_hi, res_lo);
138
+ }
139
+ }
140
+ else { /* Fast path */
141
+
142
+ *prndcstindex = 3 ;
143
+ res = z*((Poly_h[i][1]).d + z*res);
144
+ #if 1
145
+ Add12(P_hi,P_lo, ln2_times_E_HI, (Poly_h[i][0]).d );
146
+ Add12(*pres_hi, *pres_lo, P_hi, (res + ((Poly_l[i][0]).d + (ln2_times_E_LO + P_lo))));
147
+ #else
148
+ Add12(*pres_hi, *pres_lo,
149
+ ln2_times_E_HI,
150
+ (Poly_h[i][0]).d + (res + ((Poly_l[i][0]).d + ln2_times_E_LO)));
151
+ #endif
152
+ }
153
+ }
154
+
155
+
156
+
157
+
158
+
159
+ /*************************************************************
160
+ *************************************************************
161
+ * ROUNDED TO NEAREST *
162
+ *************************************************************
163
+ *************************************************************/
164
+ double log_rn(double x){
165
+ db_number y;
166
+ double res_hi,res_lo,roundcst;
167
+ int E,rndcstindex;
168
+
169
+ E=0;
170
+ y.d=x;
171
+
172
+ /* Filter cases */
173
+ if (y.i[HI] < 0x00100000){ /* x < 2^(-1022) */
174
+ if (((y.i[HI] & 0x7fffffff)|y.i[LO])==0){
175
+ return -1.0/0.0;
176
+ } /* log(+/-0) = -Inf */
177
+ if (y.i[HI] < 0){
178
+ return (x-x)/0; /* log(-x) = Nan */
179
+ }
180
+ /* Subnormal number */
181
+ E = -52;
182
+ y.d *= two52.d; /* make x a normal number */
183
+ }
184
+
185
+ if (y.i[HI] >= 0x7ff00000){
186
+ return x+x; /* Inf or Nan */
187
+ }
188
+
189
+ /* reduce to y.d such that sqrt(2)/2 < y.d < sqrt(2) */
190
+ E += (y.i[HI]>>20)-1023; /* extract the exponent */
191
+ y.i[HI] = (y.i[HI] & 0x000fffff) | 0x3ff00000; /* do exponent = 0 */
192
+ if (y.d > SQRT_2){
193
+ y.d *= 0.5;
194
+ E++;
195
+ }
196
+
197
+ /* Call the actual computation */
198
+ log_quick(&res_hi, &res_lo, &rndcstindex, &y, E);
199
+ roundcst = rncst[rndcstindex];
200
+
201
+ /* Test for rounding to the nearest */
202
+ if(res_hi == (res_hi + (res_lo * roundcst)))
203
+ return res_hi;
204
+ else {
205
+ scs_t res;
206
+ #if DEBUG
207
+ printf("Going for Accurate Phase for x=%1.50e\n",x);
208
+ #endif
209
+ scs_log(res, y, E);
210
+ scs_get_d(&res_hi, res);
211
+ return res_hi;
212
+ }
213
+ }
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+ /*************************************************************
229
+ *************************************************************
230
+ * ROUNDED TOWARD -INFINITY *
231
+ *************************************************************
232
+ *************************************************************/
233
+ double log_rd(double x){
234
+ db_number y;
235
+ double res_hi,res_lo,roundcst;
236
+ int E,rndcstindex;
237
+ scs_t res;
238
+
239
+ E=0;
240
+ y.d=x;
241
+
242
+ /* Filter cases */
243
+ if (y.i[HI] < 0x00100000){ /* x < 2^(-1022) */
244
+ if (((y.i[HI] & 0x7fffffff)|y.i[LO])==0){
245
+ return -1.0/0.0;
246
+ } /* log(+/-0) = -Inf */
247
+ if (y.i[HI] < 0){
248
+ return (x-x)/0; /* log(-x) = Nan */
249
+ }
250
+ /* Subnormal number */
251
+ E = -52;
252
+ y.d *= two52.d; /* make x as normal number = x's mantissa */
253
+ }
254
+
255
+ if (y.i[HI] >= 0x7ff00000){
256
+ return x+x; /* Inf or Nan */
257
+ }
258
+
259
+ /* The only double whose log is exactly a double */
260
+ if(x==1.0) return 0.0;
261
+
262
+ E += (y.i[HI]>>20)-1023; /* extract the exponent */
263
+ y.i[HI] = (y.i[HI] & 0x000fffff) | 0x3ff00000; /* do exponent = 0 */
264
+ if (y.d > SQRT_2){
265
+ y.d *= 0.5;
266
+ E++;
267
+ }
268
+
269
+ log_quick(&res_hi, &res_lo, &rndcstindex, &y, E);
270
+ roundcst = epsilon[rndcstindex];
271
+
272
+ TEST_AND_RETURN_RD(res_hi, res_lo, roundcst);
273
+
274
+ /* if the previous block didn't return a value, launch accurate phase */
275
+ #if DEBUG
276
+ printf("Going for Accurate Phase");
277
+ #endif
278
+ scs_log(res, y, E);
279
+ scs_get_d_minf(&res_hi, res);
280
+ return res_hi;
281
+
282
+ }
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+ /*************************************************************
291
+ *************************************************************
292
+ * ROUNDED TOWARD +INFINITY *
293
+ *************************************************************
294
+ *************************************************************/
295
+ double log_ru(double x){
296
+ db_number y;
297
+ double res_hi,res_lo,roundcst;
298
+ int E,rndcstindex;
299
+ scs_t res;
300
+
301
+ E=0;
302
+ y.d=x;
303
+
304
+ /* Filter cases */
305
+ if (y.i[HI] < 0x00100000){ /* x < 2^(-1022) */
306
+ if (((y.i[HI] & 0x7fffffff)|y.i[LO])==0){
307
+ return -1.0/0.0;
308
+ } /* log(+/-0) = -Inf */
309
+ if (y.i[HI] < 0){
310
+ return (x-x)/0; /* log(-x) = Nan */
311
+ }
312
+ /* Subnormal number */
313
+ E = -52;
314
+ y.d *= two52.d; /* make x as normal number = x's mantissa */
315
+ }
316
+
317
+ if (y.i[HI] >= 0x7ff00000){
318
+ return x+x; /* Inf or Nan */
319
+ }
320
+
321
+ /* The only double whose log is exactly a double */
322
+ if(x==1.0) return 0.0;
323
+
324
+ E += (y.i[HI]>>20)-1023; /* extract the exponent */
325
+ y.i[HI] = (y.i[HI] & 0x000fffff) | 0x3ff00000; /* do exponent = 0 */
326
+ if (y.d > SQRT_2){
327
+ y.d *= 0.5;
328
+ E++;
329
+ }
330
+
331
+ log_quick(&res_hi, &res_lo, &rndcstindex, &y, E);
332
+ roundcst = epsilon[rndcstindex];
333
+
334
+
335
+ TEST_AND_RETURN_RU(res_hi, res_lo, roundcst);
336
+
337
+ /* if the previous block didn't return a value, launch accurate phase */
338
+ #if DEBUG
339
+ printf("Going for Accurate Phase");
340
+ #endif
341
+ scs_log(res, y, E);
342
+ scs_get_d_pinf(&res_hi, res);
343
+ return res_hi;
344
+ }
345
+
346
+
347
+
348
+
349
+
350
+ /*************************************************************
351
+ *************************************************************
352
+ * ROUNDED TOWARD ZERO *
353
+ *************************************************************
354
+ *************************************************************/
355
+ double log_rz(double x){
356
+ if(x>1)
357
+ return log_rd(x);
358
+ else
359
+ return log_ru(x);
360
+ }