Chris@16
|
1 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 // Copyright 2011 John Maddock. Distributed under the Boost
|
Chris@16
|
3 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5
|
Chris@16
|
6 #ifndef BOOST_MATH_BN_MPFR_HPP
|
Chris@16
|
7 #define BOOST_MATH_BN_MPFR_HPP
|
Chris@16
|
8
|
Chris@16
|
9 #include <boost/multiprecision/number.hpp>
|
Chris@16
|
10 #include <boost/multiprecision/gmp.hpp>
|
Chris@16
|
11 #include <boost/math/special_functions/fpclassify.hpp>
|
Chris@16
|
12 #include <boost/cstdint.hpp>
|
Chris@16
|
13 #include <boost/multiprecision/detail/big_lanczos.hpp>
|
Chris@16
|
14 #include <boost/multiprecision/detail/digits.hpp>
|
Chris@16
|
15 #include <mpfr.h>
|
Chris@16
|
16 #include <cmath>
|
Chris@16
|
17 #include <algorithm>
|
Chris@16
|
18
|
Chris@16
|
19 namespace boost{
|
Chris@16
|
20 namespace multiprecision{
|
Chris@16
|
21
|
Chris@16
|
22 enum mpfr_allocation_type
|
Chris@16
|
23 {
|
Chris@16
|
24 allocate_stack,
|
Chris@16
|
25 allocate_dynamic
|
Chris@16
|
26 };
|
Chris@16
|
27
|
Chris@16
|
28 namespace backends{
|
Chris@16
|
29
|
Chris@16
|
30 template <unsigned digits10, mpfr_allocation_type AllocationType = allocate_dynamic>
|
Chris@16
|
31 struct mpfr_float_backend;
|
Chris@16
|
32
|
Chris@16
|
33 } // namespace backends
|
Chris@16
|
34
|
Chris@16
|
35 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
36 struct number_category<backends::mpfr_float_backend<digits10, AllocationType> > : public mpl::int_<number_kind_floating_point>{};
|
Chris@16
|
37
|
Chris@16
|
38 namespace backends{
|
Chris@16
|
39
|
Chris@16
|
40 namespace detail{
|
Chris@16
|
41
|
Chris@16
|
42 template <bool b>
|
Chris@16
|
43 struct mpfr_cleanup
|
Chris@16
|
44 {
|
Chris@16
|
45 struct initializer
|
Chris@16
|
46 {
|
Chris@16
|
47 initializer() {}
|
Chris@16
|
48 ~initializer(){ mpfr_free_cache(); }
|
Chris@16
|
49 void force_instantiate()const {}
|
Chris@16
|
50 };
|
Chris@16
|
51 static const initializer init;
|
Chris@16
|
52 static void force_instantiate() { init.force_instantiate(); }
|
Chris@16
|
53 };
|
Chris@16
|
54
|
Chris@16
|
55 template <bool b>
|
Chris@16
|
56 typename mpfr_cleanup<b>::initializer const mpfr_cleanup<b>::init;
|
Chris@16
|
57
|
Chris@16
|
58 inline long get_default_precision() { return 50; }
|
Chris@16
|
59
|
Chris@16
|
60 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
61 struct mpfr_float_imp;
|
Chris@16
|
62
|
Chris@16
|
63 template <unsigned digits10>
|
Chris@16
|
64 struct mpfr_float_imp<digits10, allocate_dynamic>
|
Chris@16
|
65 {
|
Chris@16
|
66 typedef mpl::list<long, long long> signed_types;
|
Chris@16
|
67 typedef mpl::list<unsigned long, unsigned long long> unsigned_types;
|
Chris@16
|
68 typedef mpl::list<double, long double> float_types;
|
Chris@16
|
69 typedef long exponent_type;
|
Chris@16
|
70
|
Chris@16
|
71 mpfr_float_imp()
|
Chris@16
|
72 {
|
Chris@16
|
73 mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
|
Chris@16
|
74 }
|
Chris@16
|
75 mpfr_float_imp(unsigned prec)
|
Chris@16
|
76 {
|
Chris@16
|
77 mpfr_init2(m_data, prec);
|
Chris@16
|
78 }
|
Chris@16
|
79
|
Chris@16
|
80 mpfr_float_imp(const mpfr_float_imp& o)
|
Chris@16
|
81 {
|
Chris@16
|
82 mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
|
Chris@16
|
83 if(o.m_data[0]._mpfr_d)
|
Chris@16
|
84 mpfr_set(m_data, o.m_data, GMP_RNDN);
|
Chris@16
|
85 }
|
Chris@16
|
86 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
Chris@16
|
87 mpfr_float_imp(mpfr_float_imp&& o) BOOST_NOEXCEPT
|
Chris@16
|
88 {
|
Chris@16
|
89 m_data[0] = o.m_data[0];
|
Chris@16
|
90 o.m_data[0]._mpfr_d = 0;
|
Chris@16
|
91 }
|
Chris@16
|
92 #endif
|
Chris@16
|
93 mpfr_float_imp& operator = (const mpfr_float_imp& o)
|
Chris@16
|
94 {
|
Chris@16
|
95 if(m_data[0]._mpfr_d == 0)
|
Chris@16
|
96 mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
|
Chris@16
|
97 if(o.m_data[0]._mpfr_d)
|
Chris@16
|
98 mpfr_set(m_data, o.m_data, GMP_RNDN);
|
Chris@16
|
99 return *this;
|
Chris@16
|
100 }
|
Chris@16
|
101 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
Chris@16
|
102 mpfr_float_imp& operator = (mpfr_float_imp&& o) BOOST_NOEXCEPT
|
Chris@16
|
103 {
|
Chris@16
|
104 mpfr_swap(m_data, o.m_data);
|
Chris@16
|
105 return *this;
|
Chris@16
|
106 }
|
Chris@16
|
107 #endif
|
Chris@16
|
108 #ifdef _MPFR_H_HAVE_INTMAX_T
|
Chris@16
|
109 mpfr_float_imp& operator = (unsigned long long i)
|
Chris@16
|
110 {
|
Chris@16
|
111 if(m_data[0]._mpfr_d == 0)
|
Chris@16
|
112 mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
|
Chris@16
|
113 mpfr_set_uj(m_data, i, GMP_RNDN);
|
Chris@16
|
114 return *this;
|
Chris@16
|
115 }
|
Chris@16
|
116 mpfr_float_imp& operator = (long long i)
|
Chris@16
|
117 {
|
Chris@16
|
118 if(m_data[0]._mpfr_d == 0)
|
Chris@16
|
119 mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
|
Chris@16
|
120 mpfr_set_sj(m_data, i, GMP_RNDN);
|
Chris@16
|
121 return *this;
|
Chris@16
|
122 }
|
Chris@16
|
123 #else
|
Chris@16
|
124 mpfr_float_imp& operator = (unsigned long long i)
|
Chris@16
|
125 {
|
Chris@16
|
126 if(m_data[0]._mpfr_d == 0)
|
Chris@16
|
127 mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
|
Chris@16
|
128 unsigned long long mask = ((1uLL << std::numeric_limits<unsigned>::digits) - 1);
|
Chris@16
|
129 unsigned shift = 0;
|
Chris@16
|
130 mpfr_t t;
|
Chris@16
|
131 mpfr_init2(t, (std::max)(static_cast<unsigned>(std::numeric_limits<unsigned long long>::digits), static_cast<unsigned>(multiprecision::detail::digits10_2_2(digits10))));
|
Chris@16
|
132 mpfr_set_ui(m_data, 0, GMP_RNDN);
|
Chris@16
|
133 while(i)
|
Chris@16
|
134 {
|
Chris@16
|
135 mpfr_set_ui(t, static_cast<unsigned>(i & mask), GMP_RNDN);
|
Chris@16
|
136 if(shift)
|
Chris@16
|
137 mpfr_mul_2exp(t, t, shift, GMP_RNDN);
|
Chris@16
|
138 mpfr_add(m_data, m_data, t, GMP_RNDN);
|
Chris@16
|
139 shift += std::numeric_limits<unsigned>::digits;
|
Chris@16
|
140 i >>= std::numeric_limits<unsigned>::digits;
|
Chris@16
|
141 }
|
Chris@16
|
142 mpfr_clear(t);
|
Chris@16
|
143 return *this;
|
Chris@16
|
144 }
|
Chris@16
|
145 mpfr_float_imp& operator = (long long i)
|
Chris@16
|
146 {
|
Chris@16
|
147 BOOST_MP_USING_ABS
|
Chris@16
|
148 if(m_data[0]._mpfr_d == 0)
|
Chris@16
|
149 mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
|
Chris@16
|
150 bool neg = i < 0;
|
Chris@16
|
151 *this = static_cast<unsigned long long>(abs(i));
|
Chris@16
|
152 if(neg)
|
Chris@16
|
153 mpfr_neg(m_data, m_data, GMP_RNDN);
|
Chris@16
|
154 return *this;
|
Chris@16
|
155 }
|
Chris@16
|
156 #endif
|
Chris@16
|
157 mpfr_float_imp& operator = (unsigned long i)
|
Chris@16
|
158 {
|
Chris@16
|
159 if(m_data[0]._mpfr_d == 0)
|
Chris@16
|
160 mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
|
Chris@16
|
161 mpfr_set_ui(m_data, i, GMP_RNDN);
|
Chris@16
|
162 return *this;
|
Chris@16
|
163 }
|
Chris@16
|
164 mpfr_float_imp& operator = (long i)
|
Chris@16
|
165 {
|
Chris@16
|
166 if(m_data[0]._mpfr_d == 0)
|
Chris@16
|
167 mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
|
Chris@16
|
168 mpfr_set_si(m_data, i, GMP_RNDN);
|
Chris@16
|
169 return *this;
|
Chris@16
|
170 }
|
Chris@16
|
171 mpfr_float_imp& operator = (double d)
|
Chris@16
|
172 {
|
Chris@16
|
173 if(m_data[0]._mpfr_d == 0)
|
Chris@16
|
174 mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
|
Chris@16
|
175 mpfr_set_d(m_data, d, GMP_RNDN);
|
Chris@16
|
176 return *this;
|
Chris@16
|
177 }
|
Chris@16
|
178 mpfr_float_imp& operator = (long double a)
|
Chris@16
|
179 {
|
Chris@16
|
180 if(m_data[0]._mpfr_d == 0)
|
Chris@16
|
181 mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
|
Chris@16
|
182 mpfr_set_ld(m_data, a, GMP_RNDN);
|
Chris@16
|
183 return *this;
|
Chris@16
|
184 }
|
Chris@16
|
185 mpfr_float_imp& operator = (const char* s)
|
Chris@16
|
186 {
|
Chris@16
|
187 if(m_data[0]._mpfr_d == 0)
|
Chris@16
|
188 mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
|
Chris@16
|
189 if(mpfr_set_str(m_data, s, 10, GMP_RNDN) != 0)
|
Chris@16
|
190 {
|
Chris@16
|
191 BOOST_THROW_EXCEPTION(std::runtime_error(std::string("Unable to parse string \"") + s + std::string("\"as a valid floating point number.")));
|
Chris@16
|
192 }
|
Chris@16
|
193 return *this;
|
Chris@16
|
194 }
|
Chris@16
|
195 void swap(mpfr_float_imp& o) BOOST_NOEXCEPT
|
Chris@16
|
196 {
|
Chris@16
|
197 mpfr_swap(m_data, o.m_data);
|
Chris@16
|
198 }
|
Chris@16
|
199 std::string str(std::streamsize digits, std::ios_base::fmtflags f)const
|
Chris@16
|
200 {
|
Chris@16
|
201 BOOST_ASSERT(m_data[0]._mpfr_d);
|
Chris@16
|
202
|
Chris@16
|
203 bool scientific = (f & std::ios_base::scientific) == std::ios_base::scientific;
|
Chris@16
|
204 bool fixed = (f & std::ios_base::fixed) == std::ios_base::fixed;
|
Chris@16
|
205
|
Chris@16
|
206 std::streamsize org_digits(digits);
|
Chris@16
|
207
|
Chris@16
|
208 if(scientific && digits)
|
Chris@16
|
209 ++digits;
|
Chris@16
|
210
|
Chris@16
|
211 std::string result;
|
Chris@16
|
212 mp_exp_t e;
|
Chris@16
|
213 if(mpfr_inf_p(m_data))
|
Chris@16
|
214 {
|
Chris@16
|
215 if(mpfr_sgn(m_data) < 0)
|
Chris@16
|
216 result = "-inf";
|
Chris@16
|
217 else if(f & std::ios_base::showpos)
|
Chris@16
|
218 result = "+inf";
|
Chris@16
|
219 else
|
Chris@16
|
220 result = "inf";
|
Chris@16
|
221 return result;
|
Chris@16
|
222 }
|
Chris@16
|
223 if(mpfr_nan_p(m_data))
|
Chris@16
|
224 {
|
Chris@16
|
225 result = "nan";
|
Chris@16
|
226 return result;
|
Chris@16
|
227 }
|
Chris@16
|
228 if(mpfr_zero_p(m_data))
|
Chris@16
|
229 {
|
Chris@16
|
230 e = 0;
|
Chris@16
|
231 result = "0";
|
Chris@16
|
232 }
|
Chris@16
|
233 else
|
Chris@16
|
234 {
|
Chris@16
|
235 char* ps = mpfr_get_str (0, &e, 10, static_cast<std::size_t>(digits), m_data, GMP_RNDN);
|
Chris@16
|
236 --e; // To match with what our formatter expects.
|
Chris@16
|
237 if(fixed && e != -1)
|
Chris@16
|
238 {
|
Chris@16
|
239 // Oops we actually need a different number of digits to what we asked for:
|
Chris@16
|
240 mpfr_free_str(ps);
|
Chris@16
|
241 digits += e + 1;
|
Chris@16
|
242 if(digits == 0)
|
Chris@16
|
243 {
|
Chris@16
|
244 // We need to get *all* the digits and then possibly round up,
|
Chris@16
|
245 // we end up with either "0" or "1" as the result.
|
Chris@16
|
246 ps = mpfr_get_str (0, &e, 10, 0, m_data, GMP_RNDN);
|
Chris@16
|
247 --e;
|
Chris@16
|
248 unsigned offset = *ps == '-' ? 1 : 0;
|
Chris@16
|
249 if(ps[offset] > '5')
|
Chris@16
|
250 {
|
Chris@16
|
251 ++e;
|
Chris@16
|
252 ps[offset] = '1';
|
Chris@16
|
253 ps[offset + 1] = 0;
|
Chris@16
|
254 }
|
Chris@16
|
255 else if(ps[offset] == '5')
|
Chris@16
|
256 {
|
Chris@16
|
257 unsigned i = offset + 1;
|
Chris@16
|
258 bool round_up = false;
|
Chris@16
|
259 while(ps[i] != 0)
|
Chris@16
|
260 {
|
Chris@16
|
261 if(ps[i] != '0')
|
Chris@16
|
262 {
|
Chris@16
|
263 round_up = true;
|
Chris@16
|
264 break;
|
Chris@16
|
265 }
|
Chris@16
|
266 }
|
Chris@16
|
267 if(round_up)
|
Chris@16
|
268 {
|
Chris@16
|
269 ++e;
|
Chris@16
|
270 ps[offset] = '1';
|
Chris@16
|
271 ps[offset + 1] = 0;
|
Chris@16
|
272 }
|
Chris@16
|
273 else
|
Chris@16
|
274 {
|
Chris@16
|
275 ps[offset] = '0';
|
Chris@16
|
276 ps[offset + 1] = 0;
|
Chris@16
|
277 }
|
Chris@16
|
278 }
|
Chris@16
|
279 else
|
Chris@16
|
280 {
|
Chris@16
|
281 ps[offset] = '0';
|
Chris@16
|
282 ps[offset + 1] = 0;
|
Chris@16
|
283 }
|
Chris@16
|
284 }
|
Chris@16
|
285 else if(digits > 0)
|
Chris@16
|
286 {
|
Chris@16
|
287 ps = mpfr_get_str (0, &e, 10, static_cast<std::size_t>(digits), m_data, GMP_RNDN);
|
Chris@16
|
288 --e; // To match with what our formatter expects.
|
Chris@16
|
289 }
|
Chris@16
|
290 else
|
Chris@16
|
291 {
|
Chris@16
|
292 ps = mpfr_get_str (0, &e, 10, 1, m_data, GMP_RNDN);
|
Chris@16
|
293 --e;
|
Chris@16
|
294 unsigned offset = *ps == '-' ? 1 : 0;
|
Chris@16
|
295 ps[offset] = '0';
|
Chris@16
|
296 ps[offset + 1] = 0;
|
Chris@16
|
297 }
|
Chris@16
|
298 }
|
Chris@16
|
299 result = ps ? ps : "0";
|
Chris@16
|
300 if(ps)
|
Chris@16
|
301 mpfr_free_str(ps);
|
Chris@16
|
302 }
|
Chris@16
|
303 boost::multiprecision::detail::format_float_string(result, e, org_digits, f, 0 != mpfr_zero_p(m_data));
|
Chris@16
|
304 return result;
|
Chris@16
|
305 }
|
Chris@16
|
306 ~mpfr_float_imp() BOOST_NOEXCEPT
|
Chris@16
|
307 {
|
Chris@16
|
308 if(m_data[0]._mpfr_d)
|
Chris@16
|
309 mpfr_clear(m_data);
|
Chris@16
|
310 detail::mpfr_cleanup<true>::force_instantiate();
|
Chris@16
|
311 }
|
Chris@16
|
312 void negate() BOOST_NOEXCEPT
|
Chris@16
|
313 {
|
Chris@16
|
314 BOOST_ASSERT(m_data[0]._mpfr_d);
|
Chris@16
|
315 mpfr_neg(m_data, m_data, GMP_RNDN);
|
Chris@16
|
316 }
|
Chris@16
|
317 template <mpfr_allocation_type AllocationType>
|
Chris@16
|
318 int compare(const mpfr_float_backend<digits10, AllocationType>& o)const BOOST_NOEXCEPT
|
Chris@16
|
319 {
|
Chris@16
|
320 BOOST_ASSERT(m_data[0]._mpfr_d && o.m_data[0]._mpfr_d);
|
Chris@16
|
321 return mpfr_cmp(m_data, o.m_data);
|
Chris@16
|
322 }
|
Chris@16
|
323 int compare(long i)const BOOST_NOEXCEPT
|
Chris@16
|
324 {
|
Chris@16
|
325 BOOST_ASSERT(m_data[0]._mpfr_d);
|
Chris@16
|
326 return mpfr_cmp_si(m_data, i);
|
Chris@16
|
327 }
|
Chris@16
|
328 int compare(unsigned long i)const BOOST_NOEXCEPT
|
Chris@16
|
329 {
|
Chris@16
|
330 BOOST_ASSERT(m_data[0]._mpfr_d);
|
Chris@16
|
331 return mpfr_cmp_ui(m_data, i);
|
Chris@16
|
332 }
|
Chris@16
|
333 template <class V>
|
Chris@16
|
334 int compare(V v)const BOOST_NOEXCEPT
|
Chris@16
|
335 {
|
Chris@16
|
336 mpfr_float_backend<digits10, allocate_dynamic> d;
|
Chris@16
|
337 d = v;
|
Chris@16
|
338 return compare(d);
|
Chris@16
|
339 }
|
Chris@16
|
340 mpfr_t& data() BOOST_NOEXCEPT
|
Chris@16
|
341 {
|
Chris@16
|
342 BOOST_ASSERT(m_data[0]._mpfr_d);
|
Chris@16
|
343 return m_data;
|
Chris@16
|
344 }
|
Chris@16
|
345 const mpfr_t& data()const BOOST_NOEXCEPT
|
Chris@16
|
346 {
|
Chris@16
|
347 BOOST_ASSERT(m_data[0]._mpfr_d);
|
Chris@16
|
348 return m_data;
|
Chris@16
|
349 }
|
Chris@16
|
350 protected:
|
Chris@16
|
351 mpfr_t m_data;
|
Chris@16
|
352 static unsigned& get_default_precision() BOOST_NOEXCEPT
|
Chris@16
|
353 {
|
Chris@16
|
354 static unsigned val = 50;
|
Chris@16
|
355 return val;
|
Chris@16
|
356 }
|
Chris@16
|
357 };
|
Chris@16
|
358
|
Chris@16
|
359 #ifdef BOOST_MSVC
|
Chris@16
|
360 #pragma warning(push)
|
Chris@16
|
361 #pragma warning(disable:4127) // Conditional expression is constant
|
Chris@16
|
362 #endif
|
Chris@16
|
363
|
Chris@16
|
364 template <unsigned digits10>
|
Chris@16
|
365 struct mpfr_float_imp<digits10, allocate_stack>
|
Chris@16
|
366 {
|
Chris@16
|
367 typedef mpl::list<long, long long> signed_types;
|
Chris@16
|
368 typedef mpl::list<unsigned long, unsigned long long> unsigned_types;
|
Chris@16
|
369 typedef mpl::list<double, long double> float_types;
|
Chris@16
|
370 typedef long exponent_type;
|
Chris@16
|
371
|
Chris@16
|
372 static const unsigned digits2 = (digits10 * 1000uL) / 301uL + ((digits10 * 1000uL) % 301 ? 2u : 1u);
|
Chris@16
|
373 static const unsigned limb_count = mpfr_custom_get_size(digits2) / sizeof(mp_limb_t);
|
Chris@16
|
374
|
Chris@16
|
375 ~mpfr_float_imp() BOOST_NOEXCEPT
|
Chris@16
|
376 {
|
Chris@16
|
377 detail::mpfr_cleanup<true>::force_instantiate();
|
Chris@16
|
378 }
|
Chris@16
|
379 mpfr_float_imp()
|
Chris@16
|
380 {
|
Chris@16
|
381 mpfr_custom_init(m_buffer, digits2);
|
Chris@16
|
382 mpfr_custom_init_set(m_data, MPFR_NAN_KIND, 0, digits2, m_buffer);
|
Chris@16
|
383 }
|
Chris@16
|
384
|
Chris@16
|
385 mpfr_float_imp(const mpfr_float_imp& o)
|
Chris@16
|
386 {
|
Chris@16
|
387 mpfr_custom_init(m_buffer, digits2);
|
Chris@16
|
388 mpfr_custom_init_set(m_data, MPFR_NAN_KIND, 0, digits2, m_buffer);
|
Chris@16
|
389 mpfr_set(m_data, o.m_data, GMP_RNDN);
|
Chris@16
|
390 }
|
Chris@16
|
391 mpfr_float_imp& operator = (const mpfr_float_imp& o)
|
Chris@16
|
392 {
|
Chris@16
|
393 mpfr_set(m_data, o.m_data, GMP_RNDN);
|
Chris@16
|
394 return *this;
|
Chris@16
|
395 }
|
Chris@16
|
396 #ifdef _MPFR_H_HAVE_INTMAX_T
|
Chris@16
|
397 mpfr_float_imp& operator = (unsigned long long i)
|
Chris@16
|
398 {
|
Chris@16
|
399 mpfr_set_uj(m_data, i, GMP_RNDN);
|
Chris@16
|
400 return *this;
|
Chris@16
|
401 }
|
Chris@16
|
402 mpfr_float_imp& operator = (long long i)
|
Chris@16
|
403 {
|
Chris@16
|
404 mpfr_set_sj(m_data, i, GMP_RNDN);
|
Chris@16
|
405 return *this;
|
Chris@16
|
406 }
|
Chris@16
|
407 #else
|
Chris@16
|
408 mpfr_float_imp& operator = (unsigned long long i)
|
Chris@16
|
409 {
|
Chris@16
|
410 unsigned long long mask = ((1uLL << std::numeric_limits<unsigned>::digits) - 1);
|
Chris@16
|
411 unsigned shift = 0;
|
Chris@16
|
412 mpfr_t t;
|
Chris@16
|
413 mp_limb_t t_limbs[limb_count];
|
Chris@16
|
414 mpfr_custom_init(t_limbs, digits2);
|
Chris@16
|
415 mpfr_custom_init_set(t, MPFR_NAN_KIND, 0, digits2, t_limbs);
|
Chris@16
|
416 mpfr_set_ui(m_data, 0, GMP_RNDN);
|
Chris@16
|
417 while(i)
|
Chris@16
|
418 {
|
Chris@16
|
419 mpfr_set_ui(t, static_cast<unsigned>(i & mask), GMP_RNDN);
|
Chris@16
|
420 if(shift)
|
Chris@16
|
421 mpfr_mul_2exp(t, t, shift, GMP_RNDN);
|
Chris@16
|
422 mpfr_add(m_data, m_data, t, GMP_RNDN);
|
Chris@16
|
423 shift += std::numeric_limits<unsigned>::digits;
|
Chris@16
|
424 i >>= std::numeric_limits<unsigned>::digits;
|
Chris@16
|
425 }
|
Chris@16
|
426 return *this;
|
Chris@16
|
427 }
|
Chris@16
|
428 mpfr_float_imp& operator = (long long i)
|
Chris@16
|
429 {
|
Chris@16
|
430 BOOST_MP_USING_ABS
|
Chris@16
|
431 bool neg = i < 0;
|
Chris@16
|
432 *this = static_cast<unsigned long long>(abs(i));
|
Chris@16
|
433 if(neg)
|
Chris@16
|
434 mpfr_neg(m_data, m_data, GMP_RNDN);
|
Chris@16
|
435 return *this;
|
Chris@16
|
436 }
|
Chris@16
|
437 #endif
|
Chris@16
|
438 mpfr_float_imp& operator = (unsigned long i)
|
Chris@16
|
439 {
|
Chris@16
|
440 mpfr_set_ui(m_data, i, GMP_RNDN);
|
Chris@16
|
441 return *this;
|
Chris@16
|
442 }
|
Chris@16
|
443 mpfr_float_imp& operator = (long i)
|
Chris@16
|
444 {
|
Chris@16
|
445 mpfr_set_si(m_data, i, GMP_RNDN);
|
Chris@16
|
446 return *this;
|
Chris@16
|
447 }
|
Chris@16
|
448 mpfr_float_imp& operator = (double d)
|
Chris@16
|
449 {
|
Chris@16
|
450 mpfr_set_d(m_data, d, GMP_RNDN);
|
Chris@16
|
451 return *this;
|
Chris@16
|
452 }
|
Chris@16
|
453 mpfr_float_imp& operator = (long double a)
|
Chris@16
|
454 {
|
Chris@16
|
455 mpfr_set_ld(m_data, a, GMP_RNDN);
|
Chris@16
|
456 return *this;
|
Chris@16
|
457 }
|
Chris@16
|
458 mpfr_float_imp& operator = (const char* s)
|
Chris@16
|
459 {
|
Chris@16
|
460 if(mpfr_set_str(m_data, s, 10, GMP_RNDN) != 0)
|
Chris@16
|
461 {
|
Chris@16
|
462 BOOST_THROW_EXCEPTION(std::runtime_error(std::string("Unable to parse string \"") + s + std::string("\"as a valid floating point number.")));
|
Chris@16
|
463 }
|
Chris@16
|
464 return *this;
|
Chris@16
|
465 }
|
Chris@16
|
466 void swap(mpfr_float_imp& o) BOOST_NOEXCEPT
|
Chris@16
|
467 {
|
Chris@16
|
468 // We have to swap by copying:
|
Chris@16
|
469 mpfr_float_imp t(*this);
|
Chris@16
|
470 *this = o;
|
Chris@16
|
471 o = t;
|
Chris@16
|
472 }
|
Chris@16
|
473 std::string str(std::streamsize digits, std::ios_base::fmtflags f)const
|
Chris@16
|
474 {
|
Chris@16
|
475 BOOST_ASSERT(m_data[0]._mpfr_d);
|
Chris@16
|
476
|
Chris@16
|
477 bool scientific = (f & std::ios_base::scientific) == std::ios_base::scientific;
|
Chris@16
|
478 bool fixed = (f & std::ios_base::fixed) == std::ios_base::fixed;
|
Chris@16
|
479
|
Chris@16
|
480 std::streamsize org_digits(digits);
|
Chris@16
|
481
|
Chris@16
|
482 if(scientific && digits)
|
Chris@16
|
483 ++digits;
|
Chris@16
|
484
|
Chris@16
|
485 std::string result;
|
Chris@16
|
486 mp_exp_t e;
|
Chris@16
|
487 if(mpfr_inf_p(m_data))
|
Chris@16
|
488 {
|
Chris@16
|
489 if(mpfr_sgn(m_data) < 0)
|
Chris@16
|
490 result = "-inf";
|
Chris@16
|
491 else if(f & std::ios_base::showpos)
|
Chris@16
|
492 result = "+inf";
|
Chris@16
|
493 else
|
Chris@16
|
494 result = "inf";
|
Chris@16
|
495 return result;
|
Chris@16
|
496 }
|
Chris@16
|
497 if(mpfr_nan_p(m_data))
|
Chris@16
|
498 {
|
Chris@16
|
499 result = "nan";
|
Chris@16
|
500 return result;
|
Chris@16
|
501 }
|
Chris@16
|
502 if(mpfr_zero_p(m_data))
|
Chris@16
|
503 {
|
Chris@16
|
504 e = 0;
|
Chris@16
|
505 result = "0";
|
Chris@16
|
506 }
|
Chris@16
|
507 else
|
Chris@16
|
508 {
|
Chris@16
|
509 char* ps = mpfr_get_str (0, &e, 10, static_cast<std::size_t>(digits), m_data, GMP_RNDN);
|
Chris@16
|
510 --e; // To match with what our formatter expects.
|
Chris@16
|
511 if(fixed && e != -1)
|
Chris@16
|
512 {
|
Chris@16
|
513 // Oops we actually need a different number of digits to what we asked for:
|
Chris@16
|
514 mpfr_free_str(ps);
|
Chris@16
|
515 digits += e + 1;
|
Chris@16
|
516 if(digits == 0)
|
Chris@16
|
517 {
|
Chris@16
|
518 // We need to get *all* the digits and then possibly round up,
|
Chris@16
|
519 // we end up with either "0" or "1" as the result.
|
Chris@16
|
520 ps = mpfr_get_str (0, &e, 10, 0, m_data, GMP_RNDN);
|
Chris@16
|
521 --e;
|
Chris@16
|
522 unsigned offset = *ps == '-' ? 1 : 0;
|
Chris@16
|
523 if(ps[offset] > '5')
|
Chris@16
|
524 {
|
Chris@16
|
525 ++e;
|
Chris@16
|
526 ps[offset] = '1';
|
Chris@16
|
527 ps[offset + 1] = 0;
|
Chris@16
|
528 }
|
Chris@16
|
529 else if(ps[offset] == '5')
|
Chris@16
|
530 {
|
Chris@16
|
531 unsigned i = offset + 1;
|
Chris@16
|
532 bool round_up = false;
|
Chris@16
|
533 while(ps[i] != 0)
|
Chris@16
|
534 {
|
Chris@16
|
535 if(ps[i] != '0')
|
Chris@16
|
536 {
|
Chris@16
|
537 round_up = true;
|
Chris@16
|
538 break;
|
Chris@16
|
539 }
|
Chris@16
|
540 }
|
Chris@16
|
541 if(round_up)
|
Chris@16
|
542 {
|
Chris@16
|
543 ++e;
|
Chris@16
|
544 ps[offset] = '1';
|
Chris@16
|
545 ps[offset + 1] = 0;
|
Chris@16
|
546 }
|
Chris@16
|
547 else
|
Chris@16
|
548 {
|
Chris@16
|
549 ps[offset] = '0';
|
Chris@16
|
550 ps[offset + 1] = 0;
|
Chris@16
|
551 }
|
Chris@16
|
552 }
|
Chris@16
|
553 else
|
Chris@16
|
554 {
|
Chris@16
|
555 ps[offset] = '0';
|
Chris@16
|
556 ps[offset + 1] = 0;
|
Chris@16
|
557 }
|
Chris@16
|
558 }
|
Chris@16
|
559 else if(digits > 0)
|
Chris@16
|
560 {
|
Chris@16
|
561 ps = mpfr_get_str (0, &e, 10, static_cast<std::size_t>(digits), m_data, GMP_RNDN);
|
Chris@16
|
562 --e; // To match with what our formatter expects.
|
Chris@16
|
563 }
|
Chris@16
|
564 else
|
Chris@16
|
565 {
|
Chris@16
|
566 ps = mpfr_get_str (0, &e, 10, 1, m_data, GMP_RNDN);
|
Chris@16
|
567 --e;
|
Chris@16
|
568 unsigned offset = *ps == '-' ? 1 : 0;
|
Chris@16
|
569 ps[offset] = '0';
|
Chris@16
|
570 ps[offset + 1] = 0;
|
Chris@16
|
571 }
|
Chris@16
|
572 }
|
Chris@16
|
573 result = ps ? ps : "0";
|
Chris@16
|
574 if(ps)
|
Chris@16
|
575 mpfr_free_str(ps);
|
Chris@16
|
576 }
|
Chris@16
|
577 boost::multiprecision::detail::format_float_string(result, e, org_digits, f, 0 != mpfr_zero_p(m_data));
|
Chris@16
|
578 return result;
|
Chris@16
|
579 }
|
Chris@16
|
580 void negate() BOOST_NOEXCEPT
|
Chris@16
|
581 {
|
Chris@16
|
582 mpfr_neg(m_data, m_data, GMP_RNDN);
|
Chris@16
|
583 }
|
Chris@16
|
584 template <mpfr_allocation_type AllocationType>
|
Chris@16
|
585 int compare(const mpfr_float_backend<digits10, AllocationType>& o)const BOOST_NOEXCEPT
|
Chris@16
|
586 {
|
Chris@16
|
587 return mpfr_cmp(m_data, o.m_data);
|
Chris@16
|
588 }
|
Chris@16
|
589 int compare(long i)const BOOST_NOEXCEPT
|
Chris@16
|
590 {
|
Chris@16
|
591 return mpfr_cmp_si(m_data, i);
|
Chris@16
|
592 }
|
Chris@16
|
593 int compare(unsigned long i)const BOOST_NOEXCEPT
|
Chris@16
|
594 {
|
Chris@16
|
595 return mpfr_cmp_ui(m_data, i);
|
Chris@16
|
596 }
|
Chris@16
|
597 template <class V>
|
Chris@16
|
598 int compare(V v)const BOOST_NOEXCEPT
|
Chris@16
|
599 {
|
Chris@16
|
600 mpfr_float_backend<digits10, allocate_stack> d;
|
Chris@16
|
601 d = v;
|
Chris@16
|
602 return compare(d);
|
Chris@16
|
603 }
|
Chris@16
|
604 mpfr_t& data() BOOST_NOEXCEPT
|
Chris@16
|
605 {
|
Chris@16
|
606 return m_data;
|
Chris@16
|
607 }
|
Chris@16
|
608 const mpfr_t& data()const BOOST_NOEXCEPT
|
Chris@16
|
609 {
|
Chris@16
|
610 return m_data;
|
Chris@16
|
611 }
|
Chris@16
|
612 protected:
|
Chris@16
|
613 mpfr_t m_data;
|
Chris@16
|
614 mp_limb_t m_buffer[limb_count];
|
Chris@16
|
615 };
|
Chris@16
|
616
|
Chris@16
|
617 #ifdef BOOST_MSVC
|
Chris@16
|
618 #pragma warning(pop)
|
Chris@16
|
619 #endif
|
Chris@16
|
620
|
Chris@16
|
621 } // namespace detail
|
Chris@16
|
622
|
Chris@16
|
623 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
624 struct mpfr_float_backend : public detail::mpfr_float_imp<digits10, AllocationType>
|
Chris@16
|
625 {
|
Chris@16
|
626 mpfr_float_backend() : detail::mpfr_float_imp<digits10, AllocationType>() {}
|
Chris@16
|
627 mpfr_float_backend(const mpfr_float_backend& o) : detail::mpfr_float_imp<digits10, AllocationType>(o) {}
|
Chris@16
|
628 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
Chris@16
|
629 mpfr_float_backend(mpfr_float_backend&& o) : detail::mpfr_float_imp<digits10, AllocationType>(static_cast<detail::mpfr_float_imp<digits10, AllocationType>&&>(o)) {}
|
Chris@16
|
630 #endif
|
Chris@16
|
631 template <unsigned D, mpfr_allocation_type AT>
|
Chris@16
|
632 mpfr_float_backend(const mpfr_float_backend<D, AT>& val, typename enable_if_c<D <= digits10>::type* = 0)
|
Chris@16
|
633 : detail::mpfr_float_imp<digits10, AllocationType>()
|
Chris@16
|
634 {
|
Chris@16
|
635 mpfr_set(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
636 }
|
Chris@16
|
637 template <unsigned D, mpfr_allocation_type AT>
|
Chris@16
|
638 explicit mpfr_float_backend(const mpfr_float_backend<D, AT>& val, typename disable_if_c<D <= digits10>::type* = 0)
|
Chris@16
|
639 : detail::mpfr_float_imp<digits10, AllocationType>()
|
Chris@16
|
640 {
|
Chris@16
|
641 mpfr_set(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
642 }
|
Chris@16
|
643 template <unsigned D>
|
Chris@16
|
644 mpfr_float_backend(const gmp_float<D>& val, typename enable_if_c<D <= digits10>::type* = 0)
|
Chris@16
|
645 : detail::mpfr_float_imp<digits10, AllocationType>()
|
Chris@16
|
646 {
|
Chris@16
|
647 mpfr_set_f(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
648 }
|
Chris@16
|
649 template <unsigned D>
|
Chris@16
|
650 mpfr_float_backend(const gmp_float<D>& val, typename disable_if_c<D <= digits10>::type* = 0)
|
Chris@16
|
651 : detail::mpfr_float_imp<digits10, AllocationType>()
|
Chris@16
|
652 {
|
Chris@16
|
653 mpfr_set_f(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
654 }
|
Chris@16
|
655 mpfr_float_backend(const gmp_int& val)
|
Chris@16
|
656 : detail::mpfr_float_imp<digits10, AllocationType>()
|
Chris@16
|
657 {
|
Chris@16
|
658 mpfr_set_z(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
659 }
|
Chris@16
|
660 mpfr_float_backend(const gmp_rational& val)
|
Chris@16
|
661 : detail::mpfr_float_imp<digits10, AllocationType>()
|
Chris@16
|
662 {
|
Chris@16
|
663 mpfr_set_q(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
664 }
|
Chris@16
|
665 mpfr_float_backend(const mpfr_t val)
|
Chris@16
|
666 : detail::mpfr_float_imp<digits10, AllocationType>()
|
Chris@16
|
667 {
|
Chris@16
|
668 mpfr_set(this->m_data, val, GMP_RNDN);
|
Chris@16
|
669 }
|
Chris@16
|
670 mpfr_float_backend(const mpf_t val)
|
Chris@16
|
671 : detail::mpfr_float_imp<digits10, AllocationType>()
|
Chris@16
|
672 {
|
Chris@16
|
673 mpfr_set_f(this->m_data, val, GMP_RNDN);
|
Chris@16
|
674 }
|
Chris@16
|
675 mpfr_float_backend(const mpz_t val)
|
Chris@16
|
676 : detail::mpfr_float_imp<digits10, AllocationType>()
|
Chris@16
|
677 {
|
Chris@16
|
678 mpfr_set_z(this->m_data, val, GMP_RNDN);
|
Chris@16
|
679 }
|
Chris@16
|
680 mpfr_float_backend(const mpq_t val)
|
Chris@16
|
681 : detail::mpfr_float_imp<digits10, AllocationType>()
|
Chris@16
|
682 {
|
Chris@16
|
683 mpfr_set_q(this->m_data, val, GMP_RNDN);
|
Chris@16
|
684 }
|
Chris@16
|
685 mpfr_float_backend& operator=(const mpfr_float_backend& o)
|
Chris@16
|
686 {
|
Chris@16
|
687 *static_cast<detail::mpfr_float_imp<digits10, AllocationType>*>(this) = static_cast<detail::mpfr_float_imp<digits10, AllocationType> const&>(o);
|
Chris@16
|
688 return *this;
|
Chris@16
|
689 }
|
Chris@16
|
690 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
Chris@16
|
691 mpfr_float_backend& operator=(mpfr_float_backend&& o) BOOST_NOEXCEPT
|
Chris@16
|
692 {
|
Chris@16
|
693 *static_cast<detail::mpfr_float_imp<digits10, AllocationType>*>(this) = static_cast<detail::mpfr_float_imp<digits10, AllocationType>&&>(o);
|
Chris@16
|
694 return *this;
|
Chris@16
|
695 }
|
Chris@16
|
696 #endif
|
Chris@16
|
697 template <class V>
|
Chris@16
|
698 mpfr_float_backend& operator=(const V& v)
|
Chris@16
|
699 {
|
Chris@16
|
700 *static_cast<detail::mpfr_float_imp<digits10, AllocationType>*>(this) = v;
|
Chris@16
|
701 return *this;
|
Chris@16
|
702 }
|
Chris@16
|
703 mpfr_float_backend& operator=(const mpfr_t val)
|
Chris@16
|
704 {
|
Chris@16
|
705 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
706 mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
|
Chris@16
|
707 mpfr_set(this->m_data, val, GMP_RNDN);
|
Chris@16
|
708 return *this;
|
Chris@16
|
709 }
|
Chris@16
|
710 mpfr_float_backend& operator=(const mpf_t val)
|
Chris@16
|
711 {
|
Chris@16
|
712 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
713 mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
|
Chris@16
|
714 mpfr_set_f(this->m_data, val, GMP_RNDN);
|
Chris@16
|
715 return *this;
|
Chris@16
|
716 }
|
Chris@16
|
717 mpfr_float_backend& operator=(const mpz_t val)
|
Chris@16
|
718 {
|
Chris@16
|
719 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
720 mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
|
Chris@16
|
721 mpfr_set_z(this->m_data, val, GMP_RNDN);
|
Chris@16
|
722 return *this;
|
Chris@16
|
723 }
|
Chris@16
|
724 mpfr_float_backend& operator=(const mpq_t val)
|
Chris@16
|
725 {
|
Chris@16
|
726 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
727 mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
|
Chris@16
|
728 mpfr_set_q(this->m_data, val, GMP_RNDN);
|
Chris@16
|
729 return *this;
|
Chris@16
|
730 }
|
Chris@16
|
731 // We don't change our precision here, this is a fixed precision type:
|
Chris@16
|
732 template <unsigned D, mpfr_allocation_type AT>
|
Chris@16
|
733 mpfr_float_backend& operator=(const mpfr_float_backend<D, AT>& val)
|
Chris@16
|
734 {
|
Chris@16
|
735 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
736 mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
|
Chris@16
|
737 mpfr_set(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
738 return *this;
|
Chris@16
|
739 }
|
Chris@16
|
740 template <unsigned D>
|
Chris@16
|
741 mpfr_float_backend& operator=(const gmp_float<D>& val)
|
Chris@16
|
742 {
|
Chris@16
|
743 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
744 mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
|
Chris@16
|
745 mpfr_set_f(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
746 return *this;
|
Chris@16
|
747 }
|
Chris@16
|
748 mpfr_float_backend& operator=(const gmp_int& val)
|
Chris@16
|
749 {
|
Chris@16
|
750 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
751 mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
|
Chris@16
|
752 mpfr_set_z(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
753 return *this;
|
Chris@16
|
754 }
|
Chris@16
|
755 mpfr_float_backend& operator=(const gmp_rational& val)
|
Chris@16
|
756 {
|
Chris@16
|
757 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
758 mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
|
Chris@16
|
759 mpfr_set_q(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
760 return *this;
|
Chris@16
|
761 }
|
Chris@16
|
762 };
|
Chris@16
|
763
|
Chris@16
|
764 template <>
|
Chris@16
|
765 struct mpfr_float_backend<0, allocate_dynamic> : public detail::mpfr_float_imp<0, allocate_dynamic>
|
Chris@16
|
766 {
|
Chris@16
|
767 mpfr_float_backend() : detail::mpfr_float_imp<0, allocate_dynamic>() {}
|
Chris@16
|
768 mpfr_float_backend(const mpfr_t val)
|
Chris@16
|
769 : detail::mpfr_float_imp<0, allocate_dynamic>(mpfr_get_prec(val))
|
Chris@16
|
770 {
|
Chris@16
|
771 mpfr_set(this->m_data, val, GMP_RNDN);
|
Chris@16
|
772 }
|
Chris@16
|
773 mpfr_float_backend(const mpf_t val)
|
Chris@16
|
774 : detail::mpfr_float_imp<0, allocate_dynamic>(mpf_get_prec(val))
|
Chris@16
|
775 {
|
Chris@16
|
776 mpfr_set_f(this->m_data, val, GMP_RNDN);
|
Chris@16
|
777 }
|
Chris@16
|
778 mpfr_float_backend(const mpz_t val)
|
Chris@16
|
779 : detail::mpfr_float_imp<0, allocate_dynamic>()
|
Chris@16
|
780 {
|
Chris@16
|
781 mpfr_set_z(this->m_data, val, GMP_RNDN);
|
Chris@16
|
782 }
|
Chris@16
|
783 mpfr_float_backend(const mpq_t val)
|
Chris@16
|
784 : detail::mpfr_float_imp<0, allocate_dynamic>()
|
Chris@16
|
785 {
|
Chris@16
|
786 mpfr_set_q(this->m_data, val, GMP_RNDN);
|
Chris@16
|
787 }
|
Chris@16
|
788 mpfr_float_backend(const mpfr_float_backend& o) : detail::mpfr_float_imp<0, allocate_dynamic>(o) {}
|
Chris@16
|
789 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
Chris@16
|
790 mpfr_float_backend(mpfr_float_backend&& o) BOOST_NOEXCEPT : detail::mpfr_float_imp<0, allocate_dynamic>(static_cast<detail::mpfr_float_imp<0, allocate_dynamic>&&>(o)) {}
|
Chris@16
|
791 #endif
|
Chris@16
|
792 mpfr_float_backend(const mpfr_float_backend& o, unsigned digits10)
|
Chris@16
|
793 : detail::mpfr_float_imp<0, allocate_dynamic>(digits10)
|
Chris@16
|
794 {
|
Chris@16
|
795 *this = o;
|
Chris@16
|
796 }
|
Chris@16
|
797 template <unsigned D>
|
Chris@16
|
798 mpfr_float_backend(const mpfr_float_backend<D>& val)
|
Chris@16
|
799 : detail::mpfr_float_imp<0, allocate_dynamic>(mpfr_get_prec(val.data()))
|
Chris@16
|
800 {
|
Chris@16
|
801 mpfr_set(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
802 }
|
Chris@16
|
803 template <unsigned D>
|
Chris@16
|
804 mpfr_float_backend(const gmp_float<D>& val)
|
Chris@16
|
805 : detail::mpfr_float_imp<0, allocate_dynamic>(mpf_get_prec(val.data()))
|
Chris@16
|
806 {
|
Chris@16
|
807 mpfr_set_f(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
808 }
|
Chris@16
|
809 mpfr_float_backend(const gmp_int& val)
|
Chris@16
|
810 : detail::mpfr_float_imp<0, allocate_dynamic>()
|
Chris@16
|
811 {
|
Chris@16
|
812 mpfr_set_z(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
813 }
|
Chris@16
|
814 mpfr_float_backend(const gmp_rational& val)
|
Chris@16
|
815 : detail::mpfr_float_imp<0, allocate_dynamic>()
|
Chris@16
|
816 {
|
Chris@16
|
817 mpfr_set_q(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
818 }
|
Chris@16
|
819
|
Chris@16
|
820 mpfr_float_backend& operator=(const mpfr_float_backend& o)
|
Chris@16
|
821 {
|
Chris@16
|
822 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
823 mpfr_init2(this->m_data, mpfr_get_prec(o.data()));
|
Chris@16
|
824 else
|
Chris@16
|
825 mpfr_set_prec(this->m_data, mpfr_get_prec(o.data()));
|
Chris@16
|
826 mpfr_set(this->m_data, o.data(), GMP_RNDN);
|
Chris@16
|
827 return *this;
|
Chris@16
|
828 }
|
Chris@16
|
829 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
Chris@16
|
830 mpfr_float_backend& operator=(mpfr_float_backend&& o) BOOST_NOEXCEPT
|
Chris@16
|
831 {
|
Chris@16
|
832 *static_cast<detail::mpfr_float_imp<0, allocate_dynamic>*>(this) = static_cast<detail::mpfr_float_imp<0, allocate_dynamic> &&>(o);
|
Chris@16
|
833 return *this;
|
Chris@16
|
834 }
|
Chris@16
|
835 #endif
|
Chris@16
|
836 template <class V>
|
Chris@16
|
837 mpfr_float_backend& operator=(const V& v)
|
Chris@16
|
838 {
|
Chris@16
|
839 *static_cast<detail::mpfr_float_imp<0, allocate_dynamic>*>(this) = v;
|
Chris@16
|
840 return *this;
|
Chris@16
|
841 }
|
Chris@16
|
842 mpfr_float_backend& operator=(const mpfr_t val)
|
Chris@16
|
843 {
|
Chris@16
|
844 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
845 mpfr_init2(this->m_data, mpfr_get_prec(val));
|
Chris@16
|
846 else
|
Chris@16
|
847 mpfr_set_prec(this->m_data, mpfr_get_prec(val));
|
Chris@16
|
848 mpfr_set(this->m_data, val, GMP_RNDN);
|
Chris@16
|
849 return *this;
|
Chris@16
|
850 }
|
Chris@16
|
851 mpfr_float_backend& operator=(const mpf_t val)
|
Chris@16
|
852 {
|
Chris@16
|
853 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
854 mpfr_init2(this->m_data, mpf_get_prec(val));
|
Chris@16
|
855 else
|
Chris@16
|
856 mpfr_set_prec(this->m_data, mpf_get_prec(val));
|
Chris@16
|
857 mpfr_set_f(this->m_data, val, GMP_RNDN);
|
Chris@16
|
858 return *this;
|
Chris@16
|
859 }
|
Chris@16
|
860 mpfr_float_backend& operator=(const mpz_t val)
|
Chris@16
|
861 {
|
Chris@16
|
862 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
863 mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(get_default_precision()));
|
Chris@16
|
864 mpfr_set_z(this->m_data, val, GMP_RNDN);
|
Chris@16
|
865 return *this;
|
Chris@16
|
866 }
|
Chris@16
|
867 mpfr_float_backend& operator=(const mpq_t val)
|
Chris@16
|
868 {
|
Chris@16
|
869 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
870 mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(get_default_precision()));
|
Chris@16
|
871 mpfr_set_q(this->m_data, val, GMP_RNDN);
|
Chris@16
|
872 return *this;
|
Chris@16
|
873 }
|
Chris@16
|
874 template <unsigned D>
|
Chris@16
|
875 mpfr_float_backend& operator=(const mpfr_float_backend<D>& val)
|
Chris@16
|
876 {
|
Chris@16
|
877 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
878 mpfr_init2(this->m_data, mpfr_get_prec(val.data()));
|
Chris@16
|
879 else
|
Chris@16
|
880 mpfr_set_prec(this->m_data, mpfr_get_prec(val.data()));
|
Chris@16
|
881 mpfr_set(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
882 return *this;
|
Chris@16
|
883 }
|
Chris@16
|
884 template <unsigned D>
|
Chris@16
|
885 mpfr_float_backend& operator=(const gmp_float<D>& val)
|
Chris@16
|
886 {
|
Chris@16
|
887 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
888 mpfr_init2(this->m_data, mpf_get_prec(val.data()));
|
Chris@16
|
889 else
|
Chris@16
|
890 mpfr_set_prec(this->m_data, mpf_get_prec(val.data()));
|
Chris@16
|
891 mpfr_set_f(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
892 return *this;
|
Chris@16
|
893 }
|
Chris@16
|
894 mpfr_float_backend& operator=(const gmp_int& val)
|
Chris@16
|
895 {
|
Chris@16
|
896 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
897 mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(get_default_precision()));
|
Chris@16
|
898 mpfr_set_z(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
899 return *this;
|
Chris@16
|
900 }
|
Chris@16
|
901 mpfr_float_backend& operator=(const gmp_rational& val)
|
Chris@16
|
902 {
|
Chris@16
|
903 if(this->m_data[0]._mpfr_d == 0)
|
Chris@16
|
904 mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(get_default_precision()));
|
Chris@16
|
905 mpfr_set_q(this->m_data, val.data(), GMP_RNDN);
|
Chris@16
|
906 return *this;
|
Chris@16
|
907 }
|
Chris@16
|
908 static unsigned default_precision() BOOST_NOEXCEPT
|
Chris@16
|
909 {
|
Chris@16
|
910 return get_default_precision();
|
Chris@16
|
911 }
|
Chris@16
|
912 static void default_precision(unsigned v) BOOST_NOEXCEPT
|
Chris@16
|
913 {
|
Chris@16
|
914 get_default_precision() = v;
|
Chris@16
|
915 }
|
Chris@16
|
916 unsigned precision()const BOOST_NOEXCEPT
|
Chris@16
|
917 {
|
Chris@16
|
918 return multiprecision::detail::digits2_2_10(mpfr_get_prec(this->m_data));
|
Chris@16
|
919 }
|
Chris@16
|
920 void precision(unsigned digits10) BOOST_NOEXCEPT
|
Chris@16
|
921 {
|
Chris@16
|
922 mpfr_prec_round(this->m_data, multiprecision::detail::digits10_2_2((digits10)), GMP_RNDN);
|
Chris@16
|
923 }
|
Chris@16
|
924 };
|
Chris@16
|
925
|
Chris@16
|
926 template <unsigned digits10, mpfr_allocation_type AllocationType, class T>
|
Chris@16
|
927 inline typename enable_if<is_arithmetic<T>, bool>::type eval_eq(const mpfr_float_backend<digits10, AllocationType>& a, const T& b) BOOST_NOEXCEPT
|
Chris@16
|
928 {
|
Chris@16
|
929 return a.compare(b) == 0;
|
Chris@16
|
930 }
|
Chris@16
|
931 template <unsigned digits10, mpfr_allocation_type AllocationType, class T>
|
Chris@16
|
932 inline typename enable_if<is_arithmetic<T>, bool>::type eval_lt(const mpfr_float_backend<digits10, AllocationType>& a, const T& b) BOOST_NOEXCEPT
|
Chris@16
|
933 {
|
Chris@16
|
934 return a.compare(b) < 0;
|
Chris@16
|
935 }
|
Chris@16
|
936 template <unsigned digits10, mpfr_allocation_type AllocationType, class T>
|
Chris@16
|
937 inline typename enable_if<is_arithmetic<T>, bool>::type eval_gt(const mpfr_float_backend<digits10, AllocationType>& a, const T& b) BOOST_NOEXCEPT
|
Chris@16
|
938 {
|
Chris@16
|
939 return a.compare(b) > 0;
|
Chris@16
|
940 }
|
Chris@16
|
941
|
Chris@16
|
942 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
943 inline void eval_add(mpfr_float_backend<D1, A1>& result, const mpfr_float_backend<D2, A2>& o)
|
Chris@16
|
944 {
|
Chris@16
|
945 mpfr_add(result.data(), result.data(), o.data(), GMP_RNDN);
|
Chris@16
|
946 }
|
Chris@16
|
947 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
948 inline void eval_subtract(mpfr_float_backend<D1, A1>& result, const mpfr_float_backend<D2, A2>& o)
|
Chris@16
|
949 {
|
Chris@16
|
950 mpfr_sub(result.data(), result.data(), o.data(), GMP_RNDN);
|
Chris@16
|
951 }
|
Chris@16
|
952 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
953 inline void eval_multiply(mpfr_float_backend<D1, A1>& result, const mpfr_float_backend<D2, A2>& o)
|
Chris@16
|
954 {
|
Chris@16
|
955 if((void*)&o == (void*)&result)
|
Chris@16
|
956 mpfr_sqr(result.data(), o.data(), GMP_RNDN);
|
Chris@16
|
957 else
|
Chris@16
|
958 mpfr_mul(result.data(), result.data(), o.data(), GMP_RNDN);
|
Chris@16
|
959 }
|
Chris@16
|
960 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
961 inline void eval_divide(mpfr_float_backend<D1, A1>& result, const mpfr_float_backend<D2, A2>& o)
|
Chris@16
|
962 {
|
Chris@16
|
963 mpfr_div(result.data(), result.data(), o.data(), GMP_RNDN);
|
Chris@16
|
964 }
|
Chris@16
|
965 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
966 inline void eval_add(mpfr_float_backend<digits10, AllocationType>& result, unsigned long i)
|
Chris@16
|
967 {
|
Chris@16
|
968 mpfr_add_ui(result.data(), result.data(), i, GMP_RNDN);
|
Chris@16
|
969 }
|
Chris@16
|
970 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
971 inline void eval_subtract(mpfr_float_backend<digits10, AllocationType>& result, unsigned long i)
|
Chris@16
|
972 {
|
Chris@16
|
973 mpfr_sub_ui(result.data(), result.data(), i, GMP_RNDN);
|
Chris@16
|
974 }
|
Chris@16
|
975 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
976 inline void eval_multiply(mpfr_float_backend<digits10, AllocationType>& result, unsigned long i)
|
Chris@16
|
977 {
|
Chris@16
|
978 mpfr_mul_ui(result.data(), result.data(), i, GMP_RNDN);
|
Chris@16
|
979 }
|
Chris@16
|
980 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
981 inline void eval_divide(mpfr_float_backend<digits10, AllocationType>& result, unsigned long i)
|
Chris@16
|
982 {
|
Chris@16
|
983 mpfr_div_ui(result.data(), result.data(), i, GMP_RNDN);
|
Chris@16
|
984 }
|
Chris@16
|
985 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
986 inline void eval_add(mpfr_float_backend<digits10, AllocationType>& result, long i)
|
Chris@16
|
987 {
|
Chris@16
|
988 if(i > 0)
|
Chris@16
|
989 mpfr_add_ui(result.data(), result.data(), i, GMP_RNDN);
|
Chris@16
|
990 else
|
Chris@16
|
991 mpfr_sub_ui(result.data(), result.data(), std::abs(i), GMP_RNDN);
|
Chris@16
|
992 }
|
Chris@16
|
993 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
994 inline void eval_subtract(mpfr_float_backend<digits10, AllocationType>& result, long i)
|
Chris@16
|
995 {
|
Chris@16
|
996 if(i > 0)
|
Chris@16
|
997 mpfr_sub_ui(result.data(), result.data(), i, GMP_RNDN);
|
Chris@16
|
998 else
|
Chris@16
|
999 mpfr_add_ui(result.data(), result.data(), std::abs(i), GMP_RNDN);
|
Chris@16
|
1000 }
|
Chris@16
|
1001 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
1002 inline void eval_multiply(mpfr_float_backend<digits10, AllocationType>& result, long i)
|
Chris@16
|
1003 {
|
Chris@16
|
1004 mpfr_mul_ui(result.data(), result.data(), std::abs(i), GMP_RNDN);
|
Chris@16
|
1005 if(i < 0)
|
Chris@16
|
1006 mpfr_neg(result.data(), result.data(), GMP_RNDN);
|
Chris@16
|
1007 }
|
Chris@16
|
1008 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
1009 inline void eval_divide(mpfr_float_backend<digits10, AllocationType>& result, long i)
|
Chris@16
|
1010 {
|
Chris@16
|
1011 mpfr_div_ui(result.data(), result.data(), std::abs(i), GMP_RNDN);
|
Chris@16
|
1012 if(i < 0)
|
Chris@16
|
1013 mpfr_neg(result.data(), result.data(), GMP_RNDN);
|
Chris@16
|
1014 }
|
Chris@16
|
1015 //
|
Chris@16
|
1016 // Specialised 3 arg versions of the basic operators:
|
Chris@16
|
1017 //
|
Chris@16
|
1018 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2, unsigned D3>
|
Chris@16
|
1019 inline void eval_add(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, const mpfr_float_backend<D3>& y)
|
Chris@16
|
1020 {
|
Chris@16
|
1021 mpfr_add(a.data(), x.data(), y.data(), GMP_RNDN);
|
Chris@16
|
1022 }
|
Chris@16
|
1023 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1024 inline void eval_add(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, unsigned long y)
|
Chris@16
|
1025 {
|
Chris@16
|
1026 mpfr_add_ui(a.data(), x.data(), y, GMP_RNDN);
|
Chris@16
|
1027 }
|
Chris@16
|
1028 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1029 inline void eval_add(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, long y)
|
Chris@16
|
1030 {
|
Chris@16
|
1031 if(y < 0)
|
Chris@16
|
1032 mpfr_sub_ui(a.data(), x.data(), -y, GMP_RNDN);
|
Chris@16
|
1033 else
|
Chris@16
|
1034 mpfr_add_ui(a.data(), x.data(), y, GMP_RNDN);
|
Chris@16
|
1035 }
|
Chris@16
|
1036 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1037 inline void eval_add(mpfr_float_backend<D1, A1>& a, unsigned long x, const mpfr_float_backend<D2, A2>& y)
|
Chris@16
|
1038 {
|
Chris@16
|
1039 mpfr_add_ui(a.data(), y.data(), x, GMP_RNDN);
|
Chris@16
|
1040 }
|
Chris@16
|
1041 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1042 inline void eval_add(mpfr_float_backend<D1, A1>& a, long x, const mpfr_float_backend<D2, A2>& y)
|
Chris@16
|
1043 {
|
Chris@16
|
1044 if(x < 0)
|
Chris@16
|
1045 {
|
Chris@16
|
1046 mpfr_ui_sub(a.data(), -x, y.data(), GMP_RNDN);
|
Chris@16
|
1047 mpfr_neg(a.data(), a.data(), GMP_RNDN);
|
Chris@16
|
1048 }
|
Chris@16
|
1049 else
|
Chris@16
|
1050 mpfr_add_ui(a.data(), y.data(), x, GMP_RNDN);
|
Chris@16
|
1051 }
|
Chris@16
|
1052 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2, unsigned D3>
|
Chris@16
|
1053 inline void eval_subtract(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, const mpfr_float_backend<D3>& y)
|
Chris@16
|
1054 {
|
Chris@16
|
1055 mpfr_sub(a.data(), x.data(), y.data(), GMP_RNDN);
|
Chris@16
|
1056 }
|
Chris@16
|
1057 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1058 inline void eval_subtract(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, unsigned long y)
|
Chris@16
|
1059 {
|
Chris@16
|
1060 mpfr_sub_ui(a.data(), x.data(), y, GMP_RNDN);
|
Chris@16
|
1061 }
|
Chris@16
|
1062 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1063 inline void eval_subtract(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, long y)
|
Chris@16
|
1064 {
|
Chris@16
|
1065 if(y < 0)
|
Chris@16
|
1066 mpfr_add_ui(a.data(), x.data(), -y, GMP_RNDN);
|
Chris@16
|
1067 else
|
Chris@16
|
1068 mpfr_sub_ui(a.data(), x.data(), y, GMP_RNDN);
|
Chris@16
|
1069 }
|
Chris@16
|
1070 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1071 inline void eval_subtract(mpfr_float_backend<D1, A1>& a, unsigned long x, const mpfr_float_backend<D2, A2>& y)
|
Chris@16
|
1072 {
|
Chris@16
|
1073 mpfr_ui_sub(a.data(), x, y.data(), GMP_RNDN);
|
Chris@16
|
1074 }
|
Chris@16
|
1075 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1076 inline void eval_subtract(mpfr_float_backend<D1, A1>& a, long x, const mpfr_float_backend<D2, A2>& y)
|
Chris@16
|
1077 {
|
Chris@16
|
1078 if(x < 0)
|
Chris@16
|
1079 {
|
Chris@16
|
1080 mpfr_add_ui(a.data(), y.data(), -x, GMP_RNDN);
|
Chris@16
|
1081 mpfr_neg(a.data(), a.data(), GMP_RNDN);
|
Chris@16
|
1082 }
|
Chris@16
|
1083 else
|
Chris@16
|
1084 mpfr_ui_sub(a.data(), x, y.data(), GMP_RNDN);
|
Chris@16
|
1085 }
|
Chris@16
|
1086
|
Chris@16
|
1087 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2, unsigned D3>
|
Chris@16
|
1088 inline void eval_multiply(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, const mpfr_float_backend<D3>& y)
|
Chris@16
|
1089 {
|
Chris@16
|
1090 if((void*)&x == (void*)&y)
|
Chris@16
|
1091 mpfr_sqr(a.data(), x.data(), GMP_RNDN);
|
Chris@16
|
1092 else
|
Chris@16
|
1093 mpfr_mul(a.data(), x.data(), y.data(), GMP_RNDN);
|
Chris@16
|
1094 }
|
Chris@16
|
1095 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1096 inline void eval_multiply(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, unsigned long y)
|
Chris@16
|
1097 {
|
Chris@16
|
1098 mpfr_mul_ui(a.data(), x.data(), y, GMP_RNDN);
|
Chris@16
|
1099 }
|
Chris@16
|
1100 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1101 inline void eval_multiply(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, long y)
|
Chris@16
|
1102 {
|
Chris@16
|
1103 if(y < 0)
|
Chris@16
|
1104 {
|
Chris@16
|
1105 mpfr_mul_ui(a.data(), x.data(), -y, GMP_RNDN);
|
Chris@16
|
1106 a.negate();
|
Chris@16
|
1107 }
|
Chris@16
|
1108 else
|
Chris@16
|
1109 mpfr_mul_ui(a.data(), x.data(), y, GMP_RNDN);
|
Chris@16
|
1110 }
|
Chris@16
|
1111 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1112 inline void eval_multiply(mpfr_float_backend<D1, A1>& a, unsigned long x, const mpfr_float_backend<D2, A2>& y)
|
Chris@16
|
1113 {
|
Chris@16
|
1114 mpfr_mul_ui(a.data(), y.data(), x, GMP_RNDN);
|
Chris@16
|
1115 }
|
Chris@16
|
1116 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1117 inline void eval_multiply(mpfr_float_backend<D1, A1>& a, long x, const mpfr_float_backend<D2, A2>& y)
|
Chris@16
|
1118 {
|
Chris@16
|
1119 if(x < 0)
|
Chris@16
|
1120 {
|
Chris@16
|
1121 mpfr_mul_ui(a.data(), y.data(), -x, GMP_RNDN);
|
Chris@16
|
1122 mpfr_neg(a.data(), a.data(), GMP_RNDN);
|
Chris@16
|
1123 }
|
Chris@16
|
1124 else
|
Chris@16
|
1125 mpfr_mul_ui(a.data(), y.data(), x, GMP_RNDN);
|
Chris@16
|
1126 }
|
Chris@16
|
1127
|
Chris@16
|
1128 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2, unsigned D3>
|
Chris@16
|
1129 inline void eval_divide(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, const mpfr_float_backend<D3>& y)
|
Chris@16
|
1130 {
|
Chris@16
|
1131 mpfr_div(a.data(), x.data(), y.data(), GMP_RNDN);
|
Chris@16
|
1132 }
|
Chris@16
|
1133 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1134 inline void eval_divide(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, unsigned long y)
|
Chris@16
|
1135 {
|
Chris@16
|
1136 mpfr_div_ui(a.data(), x.data(), y, GMP_RNDN);
|
Chris@16
|
1137 }
|
Chris@16
|
1138 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1139 inline void eval_divide(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, long y)
|
Chris@16
|
1140 {
|
Chris@16
|
1141 if(y < 0)
|
Chris@16
|
1142 {
|
Chris@16
|
1143 mpfr_div_ui(a.data(), x.data(), -y, GMP_RNDN);
|
Chris@16
|
1144 a.negate();
|
Chris@16
|
1145 }
|
Chris@16
|
1146 else
|
Chris@16
|
1147 mpfr_div_ui(a.data(), x.data(), y, GMP_RNDN);
|
Chris@16
|
1148 }
|
Chris@16
|
1149 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1150 inline void eval_divide(mpfr_float_backend<D1, A1>& a, unsigned long x, const mpfr_float_backend<D2, A2>& y)
|
Chris@16
|
1151 {
|
Chris@16
|
1152 mpfr_ui_div(a.data(), x, y.data(), GMP_RNDN);
|
Chris@16
|
1153 }
|
Chris@16
|
1154 template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1155 inline void eval_divide(mpfr_float_backend<D1, A1>& a, long x, const mpfr_float_backend<D2, A2>& y)
|
Chris@16
|
1156 {
|
Chris@16
|
1157 if(x < 0)
|
Chris@16
|
1158 {
|
Chris@16
|
1159 mpfr_ui_div(a.data(), -x, y.data(), GMP_RNDN);
|
Chris@16
|
1160 mpfr_neg(a.data(), a.data(), GMP_RNDN);
|
Chris@16
|
1161 }
|
Chris@16
|
1162 else
|
Chris@16
|
1163 mpfr_ui_div(a.data(), x, y.data(), GMP_RNDN);
|
Chris@16
|
1164 }
|
Chris@16
|
1165
|
Chris@16
|
1166 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
1167 inline bool eval_is_zero(const mpfr_float_backend<digits10, AllocationType>& val) BOOST_NOEXCEPT
|
Chris@16
|
1168 {
|
Chris@16
|
1169 return 0 != mpfr_zero_p(val.data());
|
Chris@16
|
1170 }
|
Chris@16
|
1171 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
1172 inline int eval_get_sign(const mpfr_float_backend<digits10, AllocationType>& val) BOOST_NOEXCEPT
|
Chris@16
|
1173 {
|
Chris@16
|
1174 return mpfr_sgn(val.data());
|
Chris@16
|
1175 }
|
Chris@16
|
1176
|
Chris@16
|
1177 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
1178 inline void eval_convert_to(unsigned long* result, const mpfr_float_backend<digits10, AllocationType>& val)
|
Chris@16
|
1179 {
|
Chris@16
|
1180 if(mpfr_nan_p(val.data()))
|
Chris@16
|
1181 {
|
Chris@16
|
1182 BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert NaN to integer."));
|
Chris@16
|
1183 }
|
Chris@16
|
1184 *result = mpfr_get_ui(val.data(), GMP_RNDZ);
|
Chris@16
|
1185 }
|
Chris@16
|
1186 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
1187 inline void eval_convert_to(long* result, const mpfr_float_backend<digits10, AllocationType>& val)
|
Chris@16
|
1188 {
|
Chris@16
|
1189 if(mpfr_nan_p(val.data()))
|
Chris@16
|
1190 {
|
Chris@16
|
1191 BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert NaN to integer."));
|
Chris@16
|
1192 }
|
Chris@16
|
1193 *result = mpfr_get_si(val.data(), GMP_RNDZ);
|
Chris@16
|
1194 }
|
Chris@16
|
1195 #ifdef _MPFR_H_HAVE_INTMAX_T
|
Chris@16
|
1196 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
1197 inline void eval_convert_to(unsigned long long* result, const mpfr_float_backend<digits10, AllocationType>& val)
|
Chris@16
|
1198 {
|
Chris@16
|
1199 if(mpfr_nan_p(val.data()))
|
Chris@16
|
1200 {
|
Chris@16
|
1201 BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert NaN to integer."));
|
Chris@16
|
1202 }
|
Chris@16
|
1203 *result = mpfr_get_uj(val.data(), GMP_RNDZ);
|
Chris@16
|
1204 }
|
Chris@16
|
1205 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
1206 inline void eval_convert_to(long long* result, const mpfr_float_backend<digits10, AllocationType>& val)
|
Chris@16
|
1207 {
|
Chris@16
|
1208 if(mpfr_nan_p(val.data()))
|
Chris@16
|
1209 {
|
Chris@16
|
1210 BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert NaN to integer."));
|
Chris@16
|
1211 }
|
Chris@16
|
1212 *result = mpfr_get_sj(val.data(), GMP_RNDZ);
|
Chris@16
|
1213 }
|
Chris@16
|
1214 #endif
|
Chris@16
|
1215 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
1216 inline void eval_convert_to(double* result, const mpfr_float_backend<digits10, AllocationType>& val) BOOST_NOEXCEPT
|
Chris@16
|
1217 {
|
Chris@16
|
1218 *result = mpfr_get_d(val.data(), GMP_RNDN);
|
Chris@16
|
1219 }
|
Chris@16
|
1220 template <unsigned digits10, mpfr_allocation_type AllocationType>
|
Chris@16
|
1221 inline void eval_convert_to(long double* result, const mpfr_float_backend<digits10, AllocationType>& val) BOOST_NOEXCEPT
|
Chris@16
|
1222 {
|
Chris@16
|
1223 *result = mpfr_get_ld(val.data(), GMP_RNDN);
|
Chris@16
|
1224 }
|
Chris@16
|
1225
|
Chris@16
|
1226 //
|
Chris@16
|
1227 // Native non-member operations:
|
Chris@16
|
1228 //
|
Chris@16
|
1229 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1230 inline void eval_sqrt(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val)
|
Chris@16
|
1231 {
|
Chris@16
|
1232 mpfr_sqrt(result.data(), val.data(), GMP_RNDN);
|
Chris@16
|
1233 }
|
Chris@16
|
1234
|
Chris@16
|
1235 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1236 inline void eval_abs(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val)
|
Chris@16
|
1237 {
|
Chris@16
|
1238 mpfr_abs(result.data(), val.data(), GMP_RNDN);
|
Chris@16
|
1239 }
|
Chris@16
|
1240
|
Chris@16
|
1241 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1242 inline void eval_fabs(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val)
|
Chris@16
|
1243 {
|
Chris@16
|
1244 mpfr_abs(result.data(), val.data(), GMP_RNDN);
|
Chris@16
|
1245 }
|
Chris@16
|
1246 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1247 inline void eval_ceil(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val)
|
Chris@16
|
1248 {
|
Chris@16
|
1249 mpfr_ceil(result.data(), val.data());
|
Chris@16
|
1250 }
|
Chris@16
|
1251 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1252 inline void eval_floor(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val)
|
Chris@16
|
1253 {
|
Chris@16
|
1254 mpfr_floor(result.data(), val.data());
|
Chris@16
|
1255 }
|
Chris@16
|
1256 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1257 inline void eval_trunc(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val)
|
Chris@16
|
1258 {
|
Chris@16
|
1259 if(0 == mpfr_number_p(val.data()))
|
Chris@16
|
1260 {
|
Chris@16
|
1261 result = boost::math::policies::raise_rounding_error("boost::multiprecision::trunc<%1%>(%1%)", 0, number<mpfr_float_backend<Digits10, AllocateType> >(val), number<mpfr_float_backend<Digits10, AllocateType> >(val), boost::math::policies::policy<>()).backend();
|
Chris@16
|
1262 return;
|
Chris@16
|
1263 }
|
Chris@16
|
1264 mpfr_trunc(result.data(), val.data());
|
Chris@16
|
1265 }
|
Chris@16
|
1266 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1267 inline void eval_ldexp(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val, long e)
|
Chris@16
|
1268 {
|
Chris@16
|
1269 if(e > 0)
|
Chris@16
|
1270 mpfr_mul_2exp(result.data(), val.data(), e, GMP_RNDN);
|
Chris@16
|
1271 else if(e < 0)
|
Chris@16
|
1272 mpfr_div_2exp(result.data(), val.data(), -e, GMP_RNDN);
|
Chris@16
|
1273 else
|
Chris@16
|
1274 result = val;
|
Chris@16
|
1275 }
|
Chris@16
|
1276 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1277 inline void eval_frexp(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val, int* e)
|
Chris@16
|
1278 {
|
Chris@16
|
1279 long v;
|
Chris@16
|
1280 mpfr_get_d_2exp(&v, val.data(), GMP_RNDN);
|
Chris@16
|
1281 *e = v;
|
Chris@16
|
1282 eval_ldexp(result, val, -v);
|
Chris@16
|
1283 }
|
Chris@16
|
1284 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1285 inline void eval_frexp(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val, long* e)
|
Chris@16
|
1286 {
|
Chris@16
|
1287 mpfr_get_d_2exp(e, val.data(), GMP_RNDN);
|
Chris@16
|
1288 return eval_ldexp(result, val, -*e);
|
Chris@16
|
1289 }
|
Chris@16
|
1290
|
Chris@16
|
1291 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1292 inline int eval_fpclassify(const mpfr_float_backend<Digits10, AllocateType>& val) BOOST_NOEXCEPT
|
Chris@16
|
1293 {
|
Chris@16
|
1294 return mpfr_inf_p(val.data()) ? FP_INFINITE : mpfr_nan_p(val.data()) ? FP_NAN : mpfr_zero_p(val.data()) ? FP_ZERO : FP_NORMAL;
|
Chris@16
|
1295 }
|
Chris@16
|
1296
|
Chris@16
|
1297 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1298 inline void eval_pow(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& b, const mpfr_float_backend<Digits10, AllocateType>& e)
|
Chris@16
|
1299 {
|
Chris@16
|
1300 mpfr_pow(result.data(), b.data(), e.data(), GMP_RNDN);
|
Chris@16
|
1301 }
|
Chris@16
|
1302
|
Chris@16
|
1303 #ifdef BOOST_MSVC
|
Chris@16
|
1304 //
|
Chris@16
|
1305 // The enable_if usage below doesn't work with msvc - but only when
|
Chris@16
|
1306 // certain other enable_if usages are defined first. It's a capricious
|
Chris@16
|
1307 // and rather annoying compiler bug in other words....
|
Chris@16
|
1308 //
|
Chris@16
|
1309 # define BOOST_MP_ENABLE_IF_WORKAROUND (Digits10 || !Digits10) &&
|
Chris@16
|
1310 #else
|
Chris@16
|
1311 #define BOOST_MP_ENABLE_IF_WORKAROUND
|
Chris@16
|
1312 #endif
|
Chris@16
|
1313
|
Chris@16
|
1314 template <unsigned Digits10, mpfr_allocation_type AllocateType, class Integer>
|
Chris@16
|
1315 inline typename enable_if<mpl::and_<is_signed<Integer>, mpl::bool_<BOOST_MP_ENABLE_IF_WORKAROUND (sizeof(Integer) <= sizeof(long))> > >::type
|
Chris@16
|
1316 eval_pow(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& b, const Integer& e)
|
Chris@16
|
1317 {
|
Chris@16
|
1318 mpfr_pow_si(result.data(), b.data(), e, GMP_RNDN);
|
Chris@16
|
1319 }
|
Chris@16
|
1320
|
Chris@16
|
1321 template <unsigned Digits10, mpfr_allocation_type AllocateType, class Integer>
|
Chris@16
|
1322 inline typename enable_if<mpl::and_<is_unsigned<Integer>, mpl::bool_<BOOST_MP_ENABLE_IF_WORKAROUND (sizeof(Integer) <= sizeof(long))> > >::type
|
Chris@16
|
1323 eval_pow(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& b, const Integer& e)
|
Chris@16
|
1324 {
|
Chris@16
|
1325 mpfr_pow_ui(result.data(), b.data(), e, GMP_RNDN);
|
Chris@16
|
1326 }
|
Chris@16
|
1327
|
Chris@16
|
1328 #undef BOOST_MP_ENABLE_IF_WORKAROUND
|
Chris@16
|
1329
|
Chris@16
|
1330 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1331 inline void eval_exp(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
|
Chris@16
|
1332 {
|
Chris@16
|
1333 mpfr_exp(result.data(), arg.data(), GMP_RNDN);
|
Chris@16
|
1334 }
|
Chris@16
|
1335
|
Chris@16
|
1336 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1337 inline void eval_log(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
|
Chris@16
|
1338 {
|
Chris@16
|
1339 mpfr_log(result.data(), arg.data(), GMP_RNDN);
|
Chris@16
|
1340 }
|
Chris@16
|
1341
|
Chris@16
|
1342 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1343 inline void eval_log10(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
|
Chris@16
|
1344 {
|
Chris@16
|
1345 mpfr_log10(result.data(), arg.data(), GMP_RNDN);
|
Chris@16
|
1346 }
|
Chris@16
|
1347
|
Chris@16
|
1348 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1349 inline void eval_sin(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
|
Chris@16
|
1350 {
|
Chris@16
|
1351 mpfr_sin(result.data(), arg.data(), GMP_RNDN);
|
Chris@16
|
1352 }
|
Chris@16
|
1353
|
Chris@16
|
1354 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1355 inline void eval_cos(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
|
Chris@16
|
1356 {
|
Chris@16
|
1357 mpfr_cos(result.data(), arg.data(), GMP_RNDN);
|
Chris@16
|
1358 }
|
Chris@16
|
1359
|
Chris@16
|
1360 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1361 inline void eval_tan(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
|
Chris@16
|
1362 {
|
Chris@16
|
1363 mpfr_tan(result.data(), arg.data(), GMP_RNDN);
|
Chris@16
|
1364 }
|
Chris@16
|
1365
|
Chris@16
|
1366 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1367 inline void eval_asin(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
|
Chris@16
|
1368 {
|
Chris@16
|
1369 mpfr_asin(result.data(), arg.data(), GMP_RNDN);
|
Chris@16
|
1370 }
|
Chris@16
|
1371
|
Chris@16
|
1372 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1373 inline void eval_acos(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
|
Chris@16
|
1374 {
|
Chris@16
|
1375 mpfr_acos(result.data(), arg.data(), GMP_RNDN);
|
Chris@16
|
1376 }
|
Chris@16
|
1377
|
Chris@16
|
1378 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1379 inline void eval_atan(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
|
Chris@16
|
1380 {
|
Chris@16
|
1381 mpfr_atan(result.data(), arg.data(), GMP_RNDN);
|
Chris@16
|
1382 }
|
Chris@16
|
1383
|
Chris@16
|
1384 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1385 inline void eval_atan2(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg1, const mpfr_float_backend<Digits10, AllocateType>& arg2)
|
Chris@16
|
1386 {
|
Chris@16
|
1387 mpfr_atan2(result.data(), arg1.data(), arg2.data(), GMP_RNDN);
|
Chris@16
|
1388 }
|
Chris@16
|
1389
|
Chris@16
|
1390 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1391 inline void eval_sinh(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
|
Chris@16
|
1392 {
|
Chris@16
|
1393 mpfr_sinh(result.data(), arg.data(), GMP_RNDN);
|
Chris@16
|
1394 }
|
Chris@16
|
1395
|
Chris@16
|
1396 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1397 inline void eval_cosh(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
|
Chris@16
|
1398 {
|
Chris@16
|
1399 mpfr_cosh(result.data(), arg.data(), GMP_RNDN);
|
Chris@16
|
1400 }
|
Chris@16
|
1401
|
Chris@16
|
1402 template <unsigned Digits10, mpfr_allocation_type AllocateType>
|
Chris@16
|
1403 inline void eval_tanh(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
|
Chris@16
|
1404 {
|
Chris@16
|
1405 mpfr_tanh(result.data(), arg.data(), GMP_RNDN);
|
Chris@16
|
1406 }
|
Chris@16
|
1407
|
Chris@16
|
1408 } // namespace backends
|
Chris@16
|
1409
|
Chris@16
|
1410 #ifdef BOOST_NO_SFINAE_EXPR
|
Chris@16
|
1411
|
Chris@16
|
1412 namespace detail{
|
Chris@16
|
1413
|
Chris@16
|
1414 template<unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
|
Chris@16
|
1415 struct is_explicitly_convertible<backends::mpfr_float_backend<D1, A1>, backends::mpfr_float_backend<D2, A2> > : public mpl::true_ {};
|
Chris@16
|
1416
|
Chris@16
|
1417 }
|
Chris@16
|
1418
|
Chris@16
|
1419 #endif
|
Chris@16
|
1420
|
Chris@16
|
1421 template<>
|
Chris@16
|
1422 struct number_category<detail::canonical<mpfr_t, backends::mpfr_float_backend<0> >::type> : public mpl::int_<number_kind_floating_point>{};
|
Chris@16
|
1423
|
Chris@16
|
1424 using boost::multiprecision::backends::mpfr_float_backend;
|
Chris@16
|
1425
|
Chris@16
|
1426 typedef number<mpfr_float_backend<50> > mpfr_float_50;
|
Chris@16
|
1427 typedef number<mpfr_float_backend<100> > mpfr_float_100;
|
Chris@16
|
1428 typedef number<mpfr_float_backend<500> > mpfr_float_500;
|
Chris@16
|
1429 typedef number<mpfr_float_backend<1000> > mpfr_float_1000;
|
Chris@16
|
1430 typedef number<mpfr_float_backend<0> > mpfr_float;
|
Chris@16
|
1431
|
Chris@16
|
1432 typedef number<mpfr_float_backend<50, allocate_stack> > static_mpfr_float_50;
|
Chris@16
|
1433 typedef number<mpfr_float_backend<100, allocate_stack> > static_mpfr_float_100;
|
Chris@16
|
1434
|
Chris@16
|
1435 } // namespace multiprecision
|
Chris@16
|
1436
|
Chris@16
|
1437 namespace math{
|
Chris@16
|
1438
|
Chris@16
|
1439 namespace tools{
|
Chris@16
|
1440
|
Chris@16
|
1441 template <>
|
Chris@16
|
1442 inline int digits<boost::multiprecision::mpfr_float>()
|
Chris@16
|
1443 {
|
Chris@16
|
1444 return boost::multiprecision::backends::detail::get_default_precision();
|
Chris@16
|
1445 }
|
Chris@16
|
1446 template <>
|
Chris@16
|
1447 inline int digits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, boost::multiprecision::et_off> >()
|
Chris@16
|
1448 {
|
Chris@16
|
1449 return boost::multiprecision::backends::detail::get_default_precision();
|
Chris@16
|
1450 }
|
Chris@16
|
1451
|
Chris@16
|
1452 } // namespace tools
|
Chris@16
|
1453
|
Chris@16
|
1454 namespace constants{ namespace detail{
|
Chris@16
|
1455
|
Chris@16
|
1456 template <class T> struct constant_pi;
|
Chris@16
|
1457 template <class T> struct constant_ln_two;
|
Chris@16
|
1458 template <class T> struct constant_euler;
|
Chris@16
|
1459 template <class T> struct constant_catalan;
|
Chris@16
|
1460
|
Chris@16
|
1461 namespace detail{
|
Chris@16
|
1462
|
Chris@16
|
1463 template <class T, int N>
|
Chris@16
|
1464 struct mpfr_constant_initializer
|
Chris@16
|
1465 {
|
Chris@16
|
1466 static void force_instantiate()
|
Chris@16
|
1467 {
|
Chris@16
|
1468 init.force_instantiate();
|
Chris@16
|
1469 }
|
Chris@16
|
1470 private:
|
Chris@16
|
1471 struct initializer
|
Chris@16
|
1472 {
|
Chris@16
|
1473 initializer()
|
Chris@16
|
1474 {
|
Chris@16
|
1475 T::get(mpl::int_<N>());
|
Chris@16
|
1476 }
|
Chris@16
|
1477 void force_instantiate()const{}
|
Chris@16
|
1478 };
|
Chris@16
|
1479 static const initializer init;
|
Chris@16
|
1480 };
|
Chris@16
|
1481
|
Chris@16
|
1482 template <class T, int N>
|
Chris@16
|
1483 typename mpfr_constant_initializer<T, N>::initializer const mpfr_constant_initializer<T, N>::init;
|
Chris@16
|
1484
|
Chris@16
|
1485 }
|
Chris@16
|
1486
|
Chris@16
|
1487 template<unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1488 struct constant_pi<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >
|
Chris@16
|
1489 {
|
Chris@16
|
1490 typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result_type;
|
Chris@16
|
1491 template<int N>
|
Chris@16
|
1492 static inline const result_type& get(const mpl::int_<N>&)
|
Chris@16
|
1493 {
|
Chris@16
|
1494 detail::mpfr_constant_initializer<constant_pi<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >, N>::force_instantiate();
|
Chris@16
|
1495 static result_type result;
|
Chris@16
|
1496 static bool has_init = false;
|
Chris@16
|
1497 if(!has_init)
|
Chris@16
|
1498 {
|
Chris@16
|
1499 mpfr_const_pi(result.backend().data(), GMP_RNDN);
|
Chris@16
|
1500 has_init = true;
|
Chris@16
|
1501 }
|
Chris@16
|
1502 return result;
|
Chris@16
|
1503 }
|
Chris@16
|
1504 };
|
Chris@16
|
1505 template<unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1506 struct constant_ln_two<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >
|
Chris@16
|
1507 {
|
Chris@16
|
1508 typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result_type;
|
Chris@16
|
1509 template<int N>
|
Chris@16
|
1510 static inline const result_type& get(const mpl::int_<N>&)
|
Chris@16
|
1511 {
|
Chris@16
|
1512 detail::mpfr_constant_initializer<constant_ln_two<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >, N>::force_instantiate();
|
Chris@16
|
1513 static result_type result;
|
Chris@16
|
1514 static bool init = false;
|
Chris@16
|
1515 if(!init)
|
Chris@16
|
1516 {
|
Chris@16
|
1517 mpfr_const_log2(result.backend().data(), GMP_RNDN);
|
Chris@16
|
1518 init = true;
|
Chris@16
|
1519 }
|
Chris@16
|
1520 return result;
|
Chris@16
|
1521 }
|
Chris@16
|
1522 };
|
Chris@16
|
1523 template<unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1524 struct constant_euler<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >
|
Chris@16
|
1525 {
|
Chris@16
|
1526 typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result_type;
|
Chris@16
|
1527 template<int N>
|
Chris@16
|
1528 static inline const result_type& get(const mpl::int_<N>&)
|
Chris@16
|
1529 {
|
Chris@16
|
1530 detail::mpfr_constant_initializer<constant_euler<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >, N>::force_instantiate();
|
Chris@16
|
1531 static result_type result;
|
Chris@16
|
1532 static bool init = false;
|
Chris@16
|
1533 if(!init)
|
Chris@16
|
1534 {
|
Chris@16
|
1535 mpfr_const_euler(result.backend().data(), GMP_RNDN);
|
Chris@16
|
1536 init = true;
|
Chris@16
|
1537 }
|
Chris@16
|
1538 return result;
|
Chris@16
|
1539 }
|
Chris@16
|
1540 };
|
Chris@16
|
1541 template<unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1542 struct constant_catalan<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >
|
Chris@16
|
1543 {
|
Chris@16
|
1544 typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result_type;
|
Chris@16
|
1545 template<int N>
|
Chris@16
|
1546 static inline const result_type& get(const mpl::int_<N>&)
|
Chris@16
|
1547 {
|
Chris@16
|
1548 detail::mpfr_constant_initializer<constant_catalan<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >, N>::force_instantiate();
|
Chris@16
|
1549 static result_type result;
|
Chris@16
|
1550 static bool init = false;
|
Chris@16
|
1551 if(!init)
|
Chris@16
|
1552 {
|
Chris@16
|
1553 mpfr_const_catalan(result.backend().data(), GMP_RNDN);
|
Chris@16
|
1554 init = true;
|
Chris@16
|
1555 }
|
Chris@16
|
1556 return result;
|
Chris@16
|
1557 }
|
Chris@16
|
1558 };
|
Chris@16
|
1559
|
Chris@16
|
1560 }} // namespaces
|
Chris@16
|
1561
|
Chris@16
|
1562 }} // namespaces
|
Chris@16
|
1563
|
Chris@16
|
1564 namespace std{
|
Chris@16
|
1565
|
Chris@16
|
1566 //
|
Chris@16
|
1567 // numeric_limits [partial] specializations for the types declared in this header:
|
Chris@16
|
1568 //
|
Chris@16
|
1569 template<unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1570 class numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >
|
Chris@16
|
1571 {
|
Chris@16
|
1572 typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> number_type;
|
Chris@16
|
1573 public:
|
Chris@16
|
1574 BOOST_STATIC_CONSTEXPR bool is_specialized = true;
|
Chris@16
|
1575 static number_type (min)()
|
Chris@16
|
1576 {
|
Chris@16
|
1577 initializer.do_nothing();
|
Chris@16
|
1578 static std::pair<bool, number_type> value;
|
Chris@16
|
1579 if(!value.first)
|
Chris@16
|
1580 {
|
Chris@16
|
1581 value.first = true;
|
Chris@16
|
1582 value.second = 0.5;
|
Chris@16
|
1583 mpfr_div_2exp(value.second.backend().data(), value.second.backend().data(), -mpfr_get_emin(), GMP_RNDN);
|
Chris@16
|
1584 }
|
Chris@16
|
1585 return value.second;
|
Chris@16
|
1586 }
|
Chris@16
|
1587 static number_type (max)()
|
Chris@16
|
1588 {
|
Chris@16
|
1589 initializer.do_nothing();
|
Chris@16
|
1590 static std::pair<bool, number_type> value;
|
Chris@16
|
1591 if(!value.first)
|
Chris@16
|
1592 {
|
Chris@16
|
1593 value.first = true;
|
Chris@16
|
1594 value.second = 0.5;
|
Chris@16
|
1595 mpfr_mul_2exp(value.second.backend().data(), value.second.backend().data(), mpfr_get_emax(), GMP_RNDN);
|
Chris@16
|
1596 }
|
Chris@16
|
1597 return value.second;
|
Chris@16
|
1598 }
|
Chris@16
|
1599 BOOST_STATIC_CONSTEXPR number_type lowest()
|
Chris@16
|
1600 {
|
Chris@16
|
1601 return -(max)();
|
Chris@16
|
1602 }
|
Chris@16
|
1603 BOOST_STATIC_CONSTEXPR int digits = static_cast<int>((Digits10 * 1000L) / 301L + ((Digits10 * 1000L) % 301 ? 2 : 1));
|
Chris@16
|
1604 BOOST_STATIC_CONSTEXPR int digits10 = Digits10;
|
Chris@16
|
1605 // Is this really correct???
|
Chris@16
|
1606 BOOST_STATIC_CONSTEXPR int max_digits10 = Digits10 + 2;
|
Chris@16
|
1607 BOOST_STATIC_CONSTEXPR bool is_signed = true;
|
Chris@16
|
1608 BOOST_STATIC_CONSTEXPR bool is_integer = false;
|
Chris@16
|
1609 BOOST_STATIC_CONSTEXPR bool is_exact = false;
|
Chris@16
|
1610 BOOST_STATIC_CONSTEXPR int radix = 2;
|
Chris@16
|
1611 static number_type epsilon()
|
Chris@16
|
1612 {
|
Chris@16
|
1613 initializer.do_nothing();
|
Chris@16
|
1614 static std::pair<bool, number_type> value;
|
Chris@16
|
1615 if(!value.first)
|
Chris@16
|
1616 {
|
Chris@16
|
1617 value.first = true;
|
Chris@16
|
1618 value.second = 1;
|
Chris@16
|
1619 mpfr_div_2exp(value.second.backend().data(), value.second.backend().data(), std::numeric_limits<number_type>::digits - 1, GMP_RNDN);
|
Chris@16
|
1620 }
|
Chris@16
|
1621 return value.second;
|
Chris@16
|
1622 }
|
Chris@16
|
1623 // What value should this be????
|
Chris@16
|
1624 static number_type round_error()
|
Chris@16
|
1625 {
|
Chris@16
|
1626 // returns epsilon/2
|
Chris@16
|
1627 initializer.do_nothing();
|
Chris@16
|
1628 static std::pair<bool, number_type> value;
|
Chris@16
|
1629 if(!value.first)
|
Chris@16
|
1630 {
|
Chris@16
|
1631 value.first = true;
|
Chris@16
|
1632 value.second = 1;
|
Chris@16
|
1633 mpfr_div_2exp(value.second.backend().data(), value.second.backend().data(), 1, GMP_RNDN);
|
Chris@16
|
1634 }
|
Chris@16
|
1635 return value.second;
|
Chris@16
|
1636 }
|
Chris@16
|
1637 BOOST_STATIC_CONSTEXPR long min_exponent = MPFR_EMIN_DEFAULT;
|
Chris@16
|
1638 BOOST_STATIC_CONSTEXPR long min_exponent10 = (MPFR_EMIN_DEFAULT / 1000) * 301L;
|
Chris@16
|
1639 BOOST_STATIC_CONSTEXPR long max_exponent = MPFR_EMAX_DEFAULT;
|
Chris@16
|
1640 BOOST_STATIC_CONSTEXPR long max_exponent10 = (MPFR_EMAX_DEFAULT / 1000) * 301L;
|
Chris@16
|
1641 BOOST_STATIC_CONSTEXPR bool has_infinity = true;
|
Chris@16
|
1642 BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = true;
|
Chris@16
|
1643 BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false;
|
Chris@16
|
1644 BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent;
|
Chris@16
|
1645 BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false;
|
Chris@16
|
1646 static number_type infinity()
|
Chris@16
|
1647 {
|
Chris@16
|
1648 // returns epsilon/2
|
Chris@16
|
1649 initializer.do_nothing();
|
Chris@16
|
1650 static std::pair<bool, number_type> value;
|
Chris@16
|
1651 if(!value.first)
|
Chris@16
|
1652 {
|
Chris@16
|
1653 value.first = true;
|
Chris@16
|
1654 value.second = 1;
|
Chris@16
|
1655 mpfr_set_inf(value.second.backend().data(), 1);
|
Chris@16
|
1656 }
|
Chris@16
|
1657 return value.second;
|
Chris@16
|
1658 }
|
Chris@16
|
1659 static number_type quiet_NaN()
|
Chris@16
|
1660 {
|
Chris@16
|
1661 // returns epsilon/2
|
Chris@16
|
1662 initializer.do_nothing();
|
Chris@16
|
1663 static std::pair<bool, number_type> value;
|
Chris@16
|
1664 if(!value.first)
|
Chris@16
|
1665 {
|
Chris@16
|
1666 value.first = true;
|
Chris@16
|
1667 value.second = 1;
|
Chris@16
|
1668 mpfr_set_nan(value.second.backend().data());
|
Chris@16
|
1669 }
|
Chris@16
|
1670 return value.second;
|
Chris@16
|
1671 }
|
Chris@16
|
1672 BOOST_STATIC_CONSTEXPR number_type signaling_NaN()
|
Chris@16
|
1673 {
|
Chris@16
|
1674 return number_type(0);
|
Chris@16
|
1675 }
|
Chris@16
|
1676 BOOST_STATIC_CONSTEXPR number_type denorm_min() { return number_type(0); }
|
Chris@16
|
1677 BOOST_STATIC_CONSTEXPR bool is_iec559 = false;
|
Chris@16
|
1678 BOOST_STATIC_CONSTEXPR bool is_bounded = true;
|
Chris@16
|
1679 BOOST_STATIC_CONSTEXPR bool is_modulo = false;
|
Chris@16
|
1680 BOOST_STATIC_CONSTEXPR bool traps = true;
|
Chris@16
|
1681 BOOST_STATIC_CONSTEXPR bool tinyness_before = false;
|
Chris@16
|
1682 BOOST_STATIC_CONSTEXPR float_round_style round_style = round_to_nearest;
|
Chris@16
|
1683
|
Chris@16
|
1684 private:
|
Chris@16
|
1685 struct data_initializer
|
Chris@16
|
1686 {
|
Chris@16
|
1687 data_initializer()
|
Chris@16
|
1688 {
|
Chris@16
|
1689 std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<digits10, AllocateType> > >::epsilon();
|
Chris@16
|
1690 std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<digits10, AllocateType> > >::round_error();
|
Chris@16
|
1691 (std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<digits10, AllocateType> > >::min)();
|
Chris@16
|
1692 (std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<digits10, AllocateType> > >::max)();
|
Chris@16
|
1693 std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<digits10, AllocateType> > >::infinity();
|
Chris@16
|
1694 std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<digits10, AllocateType> > >::quiet_NaN();
|
Chris@16
|
1695 }
|
Chris@16
|
1696 void do_nothing()const{}
|
Chris@16
|
1697 };
|
Chris@16
|
1698 static const data_initializer initializer;
|
Chris@16
|
1699 };
|
Chris@16
|
1700
|
Chris@16
|
1701 template<unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1702 const typename numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::data_initializer numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::initializer;
|
Chris@16
|
1703
|
Chris@16
|
1704 #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
Chris@16
|
1705
|
Chris@16
|
1706 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1707 BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::digits;
|
Chris@16
|
1708 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1709 BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::digits10;
|
Chris@16
|
1710 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1711 BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::max_digits10;
|
Chris@16
|
1712 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1713 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::is_signed;
|
Chris@16
|
1714 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1715 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::is_integer;
|
Chris@16
|
1716 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1717 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::is_exact;
|
Chris@16
|
1718 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1719 BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::radix;
|
Chris@16
|
1720 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1721 BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::min_exponent;
|
Chris@16
|
1722 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1723 BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::min_exponent10;
|
Chris@16
|
1724 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1725 BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::max_exponent;
|
Chris@16
|
1726 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1727 BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::max_exponent10;
|
Chris@16
|
1728 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1729 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::has_infinity;
|
Chris@16
|
1730 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1731 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::has_quiet_NaN;
|
Chris@16
|
1732 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1733 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::has_signaling_NaN;
|
Chris@16
|
1734 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1735 BOOST_CONSTEXPR_OR_CONST float_denorm_style numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::has_denorm;
|
Chris@16
|
1736 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1737 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::has_denorm_loss;
|
Chris@16
|
1738 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1739 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::is_iec559;
|
Chris@16
|
1740 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1741 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::is_bounded;
|
Chris@16
|
1742 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1743 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::is_modulo;
|
Chris@16
|
1744 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1745 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::traps;
|
Chris@16
|
1746 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1747 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::tinyness_before;
|
Chris@16
|
1748 template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1749 BOOST_CONSTEXPR_OR_CONST float_round_style numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::round_style;
|
Chris@16
|
1750
|
Chris@16
|
1751 #endif
|
Chris@16
|
1752
|
Chris@16
|
1753
|
Chris@16
|
1754 template<boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1755 class numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >
|
Chris@16
|
1756 {
|
Chris@16
|
1757 typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> number_type;
|
Chris@16
|
1758 public:
|
Chris@16
|
1759 BOOST_STATIC_CONSTEXPR bool is_specialized = false;
|
Chris@16
|
1760 static number_type (min)() { return number_type(0); }
|
Chris@16
|
1761 static number_type (max)() { return number_type(0); }
|
Chris@16
|
1762 static number_type lowest() { return number_type(0); }
|
Chris@16
|
1763 BOOST_STATIC_CONSTEXPR int digits = 0;
|
Chris@16
|
1764 BOOST_STATIC_CONSTEXPR int digits10 = 0;
|
Chris@16
|
1765 BOOST_STATIC_CONSTEXPR int max_digits10 = 0;
|
Chris@16
|
1766 BOOST_STATIC_CONSTEXPR bool is_signed = false;
|
Chris@16
|
1767 BOOST_STATIC_CONSTEXPR bool is_integer = false;
|
Chris@16
|
1768 BOOST_STATIC_CONSTEXPR bool is_exact = false;
|
Chris@16
|
1769 BOOST_STATIC_CONSTEXPR int radix = 0;
|
Chris@16
|
1770 static number_type epsilon() { return number_type(0); }
|
Chris@16
|
1771 static number_type round_error() { return number_type(0); }
|
Chris@16
|
1772 BOOST_STATIC_CONSTEXPR int min_exponent = 0;
|
Chris@16
|
1773 BOOST_STATIC_CONSTEXPR int min_exponent10 = 0;
|
Chris@16
|
1774 BOOST_STATIC_CONSTEXPR int max_exponent = 0;
|
Chris@16
|
1775 BOOST_STATIC_CONSTEXPR int max_exponent10 = 0;
|
Chris@16
|
1776 BOOST_STATIC_CONSTEXPR bool has_infinity = false;
|
Chris@16
|
1777 BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = false;
|
Chris@16
|
1778 BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false;
|
Chris@16
|
1779 BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent;
|
Chris@16
|
1780 BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false;
|
Chris@16
|
1781 static number_type infinity() { return number_type(0); }
|
Chris@16
|
1782 static number_type quiet_NaN() { return number_type(0); }
|
Chris@16
|
1783 static number_type signaling_NaN() { return number_type(0); }
|
Chris@16
|
1784 static number_type denorm_min() { return number_type(0); }
|
Chris@16
|
1785 BOOST_STATIC_CONSTEXPR bool is_iec559 = false;
|
Chris@16
|
1786 BOOST_STATIC_CONSTEXPR bool is_bounded = false;
|
Chris@16
|
1787 BOOST_STATIC_CONSTEXPR bool is_modulo = false;
|
Chris@16
|
1788 BOOST_STATIC_CONSTEXPR bool traps = false;
|
Chris@16
|
1789 BOOST_STATIC_CONSTEXPR bool tinyness_before = false;
|
Chris@16
|
1790 BOOST_STATIC_CONSTEXPR float_round_style round_style = round_toward_zero;
|
Chris@16
|
1791 };
|
Chris@16
|
1792
|
Chris@16
|
1793 #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
Chris@16
|
1794
|
Chris@16
|
1795 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1796 BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::digits;
|
Chris@16
|
1797 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1798 BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::digits10;
|
Chris@16
|
1799 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1800 BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::max_digits10;
|
Chris@16
|
1801 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1802 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::is_signed;
|
Chris@16
|
1803 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1804 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::is_integer;
|
Chris@16
|
1805 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1806 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::is_exact;
|
Chris@16
|
1807 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1808 BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::radix;
|
Chris@16
|
1809 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1810 BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::min_exponent;
|
Chris@16
|
1811 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1812 BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::min_exponent10;
|
Chris@16
|
1813 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1814 BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::max_exponent;
|
Chris@16
|
1815 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1816 BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::max_exponent10;
|
Chris@16
|
1817 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1818 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::has_infinity;
|
Chris@16
|
1819 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1820 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::has_quiet_NaN;
|
Chris@16
|
1821 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1822 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::has_signaling_NaN;
|
Chris@16
|
1823 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1824 BOOST_CONSTEXPR_OR_CONST float_denorm_style numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::has_denorm;
|
Chris@16
|
1825 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1826 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::has_denorm_loss;
|
Chris@16
|
1827 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1828 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::is_iec559;
|
Chris@16
|
1829 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1830 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::is_bounded;
|
Chris@16
|
1831 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1832 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::is_modulo;
|
Chris@16
|
1833 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1834 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::traps;
|
Chris@16
|
1835 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1836 BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::tinyness_before;
|
Chris@16
|
1837 template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
Chris@16
|
1838 BOOST_CONSTEXPR_OR_CONST float_round_style numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::round_style;
|
Chris@16
|
1839
|
Chris@16
|
1840 #endif
|
Chris@16
|
1841 } // namespace std
|
Chris@16
|
1842 #endif
|