]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/multiprecision/detail/generic_interconvert.hpp
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / boost / boost / multiprecision / detail / generic_interconvert.hpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright 2011 John Maddock. Distributed under the Boost
3 // Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #ifndef BOOST_MP_GENERIC_INTERCONVERT_HPP
7 #define BOOST_MP_GENERIC_INTERCONVERT_HPP
8
9 #include <cmath>
10 #include <limits>
11 #include <boost/multiprecision/detail/standalone_config.hpp>
12 #include <boost/multiprecision/detail/default_ops.hpp>
13 #include <boost/multiprecision/detail/no_exceptions_support.hpp>
14 #include <boost/multiprecision/detail/assert.hpp>
15 #include <boost/multiprecision/detail/functions/trunc.hpp>
16
17 #ifdef BOOST_MSVC
18 #pragma warning(push)
19 #pragma warning(disable : 4127 6326)
20 #endif
21
22 namespace boost { namespace multiprecision { namespace detail {
23
24 template <class To, class From>
25 inline To do_cast(const From& from)
26 {
27 return static_cast<To>(from);
28 }
29 template <class To, class B, ::boost::multiprecision::expression_template_option et>
30 inline To do_cast(const number<B, et>& from)
31 {
32 return from.template convert_to<To>();
33 }
34
35 template <class To, class From>
36 void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_floating_point>& /*to_type*/, const std::integral_constant<int, number_kind_integer>& /*from_type*/)
37 {
38 using default_ops::eval_add;
39 using default_ops::eval_bitwise_and;
40 using default_ops::eval_convert_to;
41 using default_ops::eval_get_sign;
42 using default_ops::eval_is_zero;
43 using default_ops::eval_ldexp;
44 using default_ops::eval_right_shift;
45 // smallest unsigned type handled natively by "From" is likely to be it's limb_type:
46 using l_limb_type = typename canonical<unsigned char, From>::type;
47 // get the corresponding type that we can assign to "To":
48 using to_type = typename canonical<l_limb_type, To>::type;
49 From t(from);
50 bool is_neg = eval_get_sign(t) < 0;
51 if (is_neg)
52 t.negate();
53 // Pick off the first limb:
54 l_limb_type limb;
55 l_limb_type mask = static_cast<l_limb_type>(~static_cast<l_limb_type>(0));
56 From fl;
57 eval_bitwise_and(fl, t, mask);
58 eval_convert_to(&limb, fl);
59 to = static_cast<to_type>(limb);
60 eval_right_shift(t, std::numeric_limits<l_limb_type>::digits);
61 //
62 // Then keep picking off more limbs until "t" is zero:
63 //
64 To l;
65 unsigned shift = std::numeric_limits<l_limb_type>::digits;
66 while (!eval_is_zero(t))
67 {
68 eval_bitwise_and(fl, t, mask);
69 eval_convert_to(&limb, fl);
70 l = static_cast<to_type>(limb);
71 eval_right_shift(t, std::numeric_limits<l_limb_type>::digits);
72 eval_ldexp(l, l, shift);
73 eval_add(to, l);
74 shift += std::numeric_limits<l_limb_type>::digits;
75 }
76 //
77 // Finish off by setting the sign:
78 //
79 if (is_neg)
80 to.negate();
81 }
82
83 template <class To, class From>
84 void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_integer>& /*to_type*/, const std::integral_constant<int, number_kind_integer>& /*from_type*/)
85 {
86 using default_ops::eval_bitwise_and;
87 using default_ops::eval_bitwise_or;
88 using default_ops::eval_convert_to;
89 using default_ops::eval_get_sign;
90 using default_ops::eval_is_zero;
91 using default_ops::eval_left_shift;
92 using default_ops::eval_right_shift;
93 // smallest unsigned type handled natively by "From" is likely to be it's limb_type:
94 using limb_type = typename canonical<unsigned char, From>::type;
95 // get the corresponding type that we can assign to "To":
96 using to_type = typename canonical<limb_type, To>::type;
97 From t(from);
98 bool is_neg = eval_get_sign(t) < 0;
99 if (is_neg)
100 t.negate();
101 // Pick off the first limb:
102 limb_type limb;
103 limb_type mask = static_cast<limb_type>(~static_cast<limb_type>(0));
104 From fl;
105 eval_bitwise_and(fl, t, mask);
106 eval_convert_to(&limb, fl);
107 to = static_cast<to_type>(limb);
108 eval_right_shift(t, std::numeric_limits<limb_type>::digits);
109 //
110 // Then keep picking off more limbs until "t" is zero:
111 //
112 To l;
113 unsigned shift = std::numeric_limits<limb_type>::digits;
114 while (!eval_is_zero(t))
115 {
116 eval_bitwise_and(fl, t, mask);
117 eval_convert_to(&limb, fl);
118 l = static_cast<to_type>(limb);
119 eval_right_shift(t, std::numeric_limits<limb_type>::digits);
120 eval_left_shift(l, shift);
121 eval_bitwise_or(to, l);
122 shift += std::numeric_limits<limb_type>::digits;
123 }
124 //
125 // Finish off by setting the sign:
126 //
127 if (is_neg)
128 to.negate();
129 }
130
131 template <class To, class From>
132 void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_floating_point>& /*to_type*/, const std::integral_constant<int, number_kind_floating_point>& /*from_type*/)
133 {
134 #ifdef BOOST_MSVC
135 #pragma warning(push)
136 //#pragma warning(disable : 4127)
137 #endif
138 //
139 // The code here only works when the radix of "From" is 2, we could try shifting by other
140 // radixes but it would complicate things.... use a string conversion when the radix is other
141 // than 2:
142 //
143 BOOST_IF_CONSTEXPR(std::numeric_limits<number<From> >::radix != 2)
144 {
145 to = from.str(0, std::ios_base::fmtflags()).c_str();
146 return;
147 }
148 else
149 {
150 using ui_type = typename canonical<unsigned char, To>::type;
151
152 using default_ops::eval_add;
153 using default_ops::eval_convert_to;
154 using default_ops::eval_fpclassify;
155 using default_ops::eval_get_sign;
156 using default_ops::eval_is_zero;
157 using default_ops::eval_subtract;
158
159 //
160 // First classify the input, then handle the special cases:
161 //
162 int c = eval_fpclassify(from);
163
164 if (c == static_cast<int>(FP_ZERO))
165 {
166 to = ui_type(0);
167 return;
168 }
169 else if (c == static_cast<int>(FP_NAN))
170 {
171 to = static_cast<const char*>("nan");
172 return;
173 }
174 else if (c == static_cast<int>(FP_INFINITE))
175 {
176 to = static_cast<const char*>("inf");
177 if (eval_get_sign(from) < 0)
178 to.negate();
179 return;
180 }
181
182 typename From::exponent_type e;
183 From f, term;
184 to = ui_type(0);
185
186 eval_frexp(f, from, &e);
187
188 constexpr const int shift = std::numeric_limits<std::intmax_t>::digits - 1;
189
190 while (!eval_is_zero(f))
191 {
192 // extract int sized bits from f:
193 eval_ldexp(f, f, shift);
194 eval_floor(term, f);
195 e -= shift;
196 eval_ldexp(to, to, shift);
197 typename boost::multiprecision::detail::canonical<std::intmax_t, To>::type ll;
198 eval_convert_to(&ll, term);
199 eval_add(to, ll);
200 eval_subtract(f, term);
201 }
202 using to_exponent = typename To::exponent_type;
203 if (e > (std::numeric_limits<to_exponent>::max)())
204 {
205 to = static_cast<const char*>("inf");
206 if (eval_get_sign(from) < 0)
207 to.negate();
208 return;
209 }
210 if (e < (std::numeric_limits<to_exponent>::min)())
211 {
212 to = ui_type(0);
213 if (eval_get_sign(from) < 0)
214 to.negate();
215 return;
216 }
217 eval_ldexp(to, to, static_cast<to_exponent>(e));
218 }
219 #ifdef BOOST_MSVC
220 #pragma warning(pop)
221 #endif
222 }
223
224 template <class To, class From>
225 void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_rational>& /*to_type*/, const std::integral_constant<int, number_kind_rational>& /*from_type*/)
226 {
227 using to_component_type = typename component_type<number<To> >::type;
228
229 number<From> t(from);
230 to_component_type n(numerator(t)), d(denominator(t));
231 using default_ops::assign_components;
232 assign_components(to, n.backend(), d.backend());
233 }
234
235 template <class To, class From>
236 void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_rational>& /*to_type*/, const std::integral_constant<int, number_kind_integer>& /*from_type*/)
237 {
238 using to_component_type = typename component_type<number<To> >::type;
239
240 number<From> t(from);
241 to_component_type n(t), d(1);
242 using default_ops::assign_components;
243 assign_components(to, n.backend(), d.backend());
244 }
245
246 template <class LargeInteger>
247 inline typename std::enable_if<is_signed_number<LargeInteger>::value>::type make_positive(LargeInteger& val)
248 {
249 if (val.sign() < 0)
250 val = -val;
251 }
252 template <class LargeInteger>
253 inline typename std::enable_if<!is_signed_number<LargeInteger>::value>::type make_positive(LargeInteger&){}
254
255 template <class R, class LargeInteger>
256 R safe_convert_to_float(const LargeInteger& i)
257 {
258 using std::ldexp;
259 if (!i)
260 return R(0);
261 BOOST_IF_CONSTEXPR(std::numeric_limits<R>::is_specialized && std::numeric_limits<R>::max_exponent)
262 {
263 LargeInteger val(i);
264 make_positive(val);
265 std::size_t mb = msb(val);
266 if (mb >= std::numeric_limits<R>::max_exponent)
267 {
268 int scale_factor = static_cast<int>(mb) + 1 - std::numeric_limits<R>::max_exponent;
269 BOOST_MP_ASSERT(scale_factor >= 1);
270 val >>= scale_factor;
271 R result = val.template convert_to<R>();
272 BOOST_IF_CONSTEXPR(std::numeric_limits<R>::digits == 0 || std::numeric_limits<R>::digits >= std::numeric_limits<R>::max_exponent)
273 {
274 //
275 // Calculate and add on the remainder, only if there are more
276 // digits in the mantissa that the size of the exponent, in
277 // other words if we are dropping digits in the conversion
278 // otherwise:
279 //
280 LargeInteger remainder(i);
281 remainder &= (LargeInteger(1) << scale_factor) - 1;
282 result += ldexp(safe_convert_to_float<R>(remainder), -scale_factor);
283 }
284 return i.sign() < 0 ? static_cast<R>(-result) : result;
285 }
286 }
287 return i.template convert_to<R>();
288 }
289
290 template <class To, class Integer>
291 inline typename std::enable_if<!(is_number<To>::value || std::is_floating_point<To>::value)>::type
292 generic_convert_rational_to_float_imp(To& result, const Integer& n, const Integer& d, const std::integral_constant<bool, true>&)
293 {
294 //
295 // If we get here, then there's something about one type or the other
296 // that prevents an exactly rounded result from being calculated
297 // (or at least it's not clear how to implement such a thing).
298 //
299 using default_ops::eval_divide;
300 number<To> fn(safe_convert_to_float<number<To> >(n)), fd(safe_convert_to_float<number<To> >(d));
301 eval_divide(result, fn.backend(), fd.backend());
302 }
303 template <class To, class Integer>
304 inline typename std::enable_if<is_number<To>::value || std::is_floating_point<To>::value>::type
305 generic_convert_rational_to_float_imp(To& result, const Integer& n, const Integer& d, const std::integral_constant<bool, true>&)
306 {
307 //
308 // If we get here, then there's something about one type or the other
309 // that prevents an exactly rounded result from being calculated
310 // (or at least it's not clear how to implement such a thing).
311 //
312 To fd(safe_convert_to_float<To>(d));
313 result = safe_convert_to_float<To>(n);
314 result /= fd;
315 }
316
317 template <class To, class Integer>
318 typename std::enable_if<is_number<To>::value || std::is_floating_point<To>::value>::type
319 generic_convert_rational_to_float_imp(To& result, Integer& num, Integer& denom, const std::integral_constant<bool, false>&)
320 {
321 //
322 // If we get here, then the precision of type To is known, and the integer type is unbounded
323 // so we can use integer division plus manipulation of the remainder to get an exactly
324 // rounded result.
325 //
326 if (num == 0)
327 {
328 result = 0;
329 return;
330 }
331 bool s = false;
332 if (num < 0)
333 {
334 s = true;
335 num = -num;
336 }
337 std::ptrdiff_t denom_bits = msb(denom);
338 std::ptrdiff_t shift = std::numeric_limits<To>::digits + denom_bits - msb(num);
339 if (shift > 0)
340 num <<= shift;
341 else if (shift < 0)
342 denom <<= boost::multiprecision::detail::unsigned_abs(shift);
343 Integer q, r;
344 divide_qr(num, denom, q, r);
345 std::ptrdiff_t q_bits = msb(q);
346 if (q_bits == std::numeric_limits<To>::digits - 1)
347 {
348 //
349 // Round up if 2 * r > denom:
350 //
351 r <<= 1;
352 int c = r.compare(denom);
353 if (c > 0)
354 ++q;
355 else if ((c == 0) && (q & 1u))
356 {
357 ++q;
358 }
359 }
360 else
361 {
362 BOOST_MP_ASSERT(q_bits == std::numeric_limits<To>::digits);
363 //
364 // We basically already have the rounding info:
365 //
366 if (q & 1u)
367 {
368 if (r || (q & 2u))
369 ++q;
370 }
371 }
372 using std::ldexp;
373 result = do_cast<To>(q);
374 result = ldexp(result, static_cast<int>(-shift));
375 if (s)
376 result = -result;
377 }
378 template <class To, class Integer>
379 inline typename std::enable_if<!(is_number<To>::value || std::is_floating_point<To>::value)>::type
380 generic_convert_rational_to_float_imp(To& result, Integer& num, Integer& denom, const std::integral_constant<bool, false>& tag)
381 {
382 number<To> t;
383 generic_convert_rational_to_float_imp(t, num, denom, tag);
384 result = t.backend();
385 }
386
387 template <class To, class From>
388 inline void generic_convert_rational_to_float(To& result, const From& f)
389 {
390 //
391 // Type From is always a Backend to number<>, or an
392 // instance of number<>, but we allow
393 // To to be either a Backend type, or a real number type,
394 // that way we can call this from generic conversions, and
395 // from specific conversions to built in types.
396 //
397 using actual_from_type = typename std::conditional<is_number<From>::value, From, number<From> >::type ;
398 using actual_to_type = typename std::conditional<is_number<To>::value || std::is_floating_point<To>::value, To, number<To> >::type ;
399 using integer_type = typename component_type<actual_from_type>::type ;
400 using dispatch_tag = std::integral_constant<bool, !std::numeric_limits<integer_type>::is_specialized || std::numeric_limits<integer_type>::is_bounded || !std::numeric_limits<actual_to_type>::is_specialized || !std::numeric_limits<actual_to_type>::is_bounded || (std::numeric_limits<actual_to_type>::radix != 2)>;
401
402 integer_type n(numerator(static_cast<actual_from_type>(f))), d(denominator(static_cast<actual_from_type>(f)));
403 generic_convert_rational_to_float_imp(result, n, d, dispatch_tag());
404 }
405
406 template <class To, class From>
407 inline void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_floating_point>& /*to_type*/, const std::integral_constant<int, number_kind_rational>& /*from_type*/)
408 {
409 generic_convert_rational_to_float(to, from);
410 }
411
412 template <class To, class From>
413 void generic_interconvert_float2rational(To& to, const From& from, const std::integral_constant<int, 2>& /*radix*/)
414 {
415 using std::ldexp;
416 using std::frexp;
417 using ui_type = typename std::tuple_element<0, typename To::unsigned_types>::type;
418 constexpr const int shift = std::numeric_limits<long long>::digits;
419 typename From::exponent_type e;
420 typename component_type<number<To>>::type num, denom;
421 number<From> val(from);
422 val = frexp(val, &e);
423 while (val)
424 {
425 val = ldexp(val, shift);
426 e -= shift;
427 long long ll = boost::multiprecision::detail::lltrunc(val);
428 val -= ll;
429 num <<= shift;
430 num += ll;
431 }
432 denom = ui_type(1u);
433 if (e < 0)
434 denom <<= -e;
435 else if (e > 0)
436 num <<= e;
437 assign_components(to, num.backend(), denom.backend());
438 }
439
440 template <class To, class From, int Radix>
441 void generic_interconvert_float2rational(To& to, const From& from, const std::integral_constant<int, Radix>& /*radix*/)
442 {
443 using std::ilogb;
444 using std::scalbn;
445 using std::pow;
446 using std::abs;
447 //
448 // This is almost the same as the binary case above, but we have to use
449 // scalbn and ilogb rather than ldexp and frexp, we also only extract
450 // one Radix digit at a time which is terribly inefficient!
451 //
452 using ui_type = typename std::tuple_element<0, typename To::unsigned_types>::type;
453 typename From::exponent_type e;
454 typename component_type<number<To>>::type num, denom;
455 number<From> val(from);
456
457 if (!val)
458 {
459 to = ui_type(0u);
460 return;
461 }
462
463 e = ilogb(val);
464 val = scalbn(val, -e);
465 while (val)
466 {
467 long long ll = boost::multiprecision::detail::lltrunc(val);
468 val -= ll;
469 val = scalbn(val, 1);
470 num *= Radix;
471 num += ll;
472 --e;
473 }
474 ++e;
475 denom = ui_type(Radix);
476 denom = pow(denom, abs(e));
477 if (e > 0)
478 {
479 num *= denom;
480 denom = 1;
481 }
482 assign_components(to, num.backend(), denom.backend());
483 }
484
485 template <class To, class From>
486 void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_rational>& /*to_type*/, const std::integral_constant<int, number_kind_floating_point>& /*from_type*/)
487 {
488 generic_interconvert_float2rational(to, from, std::integral_constant<int, std::numeric_limits<number<From> >::is_specialized ? std::numeric_limits<number<From> >::radix : 2>());
489 }
490
491 template <class To, class From>
492 void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_integer>& /*to_type*/, const std::integral_constant<int, number_kind_rational>& /*from_type*/)
493 {
494 number<From> t(from);
495 number<To> result(numerator(t) / denominator(t));
496 to = result.backend();
497 }
498
499 template <class To, class From>
500 void generic_interconvert_float2int(To& to, const From& from, const std::integral_constant<int, 2>& /*radix*/)
501 {
502 using std::frexp;
503 using std::ldexp;
504
505 using exponent_type = typename From::exponent_type;
506 constexpr const exponent_type shift = std::numeric_limits<long long>::digits;
507 exponent_type e;
508 number<To> num(0u);
509 number<From> val(from);
510 val = frexp(val, &e);
511 bool neg = false;
512 if (val.sign() < 0)
513 {
514 val.backend().negate();
515 neg = true;
516 }
517 while (e > 0)
518 {
519 exponent_type s = (std::min)(e, shift);
520 val = ldexp(val, s);
521 e -= s;
522 long long ll = boost::multiprecision::detail::lltrunc(val);
523 val -= ll;
524 num <<= s;
525 num += ll;
526 }
527 to = num.backend();
528 if (neg)
529 to.negate();
530 }
531
532 template <class To, class From, int Radix>
533 void generic_interconvert_float2int(To& to, const From& from, const std::integral_constant<int, Radix>& /*radix*/)
534 {
535 using std::ilogb;
536 using std::scalbn;
537 //
538 // This is almost the same as the binary case above, but we have to use
539 // scalbn and ilogb rather than ldexp and frexp, we also only extract
540 // one Radix digit at a time which is terribly inefficient!
541 //
542 typename From::exponent_type e;
543 number<To> num(0u);
544 number<From> val(from);
545 e = ilogb(val);
546 val = scalbn(val, -e);
547 while (e >= 0)
548 {
549 long long ll = boost::multiprecision::detail::lltrunc(val);
550 val -= ll;
551 val = scalbn(val, 1);
552 num *= Radix;
553 num += ll;
554 --e;
555 }
556 to = num.backend();
557 }
558
559 template <class To, class From>
560 void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_integer>& /*to_type*/, const std::integral_constant<int, number_kind_floating_point>& /*from_type*/)
561 {
562 generic_interconvert_float2int(to, from, std::integral_constant<int, (std::numeric_limits<number<From> >::is_specialized ? std::numeric_limits<number<From> >::radix : 2)>());
563 }
564
565 template <class To, class From, class tag>
566 void generic_interconvert_complex_to_scalar(To& to, const From& from, const std::integral_constant<bool, true>&, const tag&)
567 {
568 // We just want the real part, and "to" is the correct type already:
569 eval_real(to, from);
570
571 To im;
572 eval_imag(im, from);
573 if (!eval_is_zero(im))
574 BOOST_MP_THROW_EXCEPTION(std::runtime_error("Could not convert imaginary number to scalar."));
575 }
576 template <class To, class From>
577 void generic_interconvert_complex_to_scalar(To& to, const From& from, const std::integral_constant<bool, false>&, const std::integral_constant<bool, true>&)
578 {
579 using component_number = typename component_type<number<From> >::type;
580 using component_backend = typename component_number::backend_type ;
581 //
582 // Get the real part and copy-construct the result from it:
583 //
584 scoped_precision_options<component_number> scope(from);
585 component_backend r;
586 generic_interconvert_complex_to_scalar(r, from, std::integral_constant<bool, true>(), std::integral_constant<bool, true>());
587 to = r;
588 }
589 template <class To, class From>
590 void generic_interconvert_complex_to_scalar(To& to, const From& from, const std::integral_constant<bool, false>&, const std::integral_constant<bool, false>&)
591 {
592 using component_number = typename component_type<number<From> >::type;
593 using component_backend = typename component_number::backend_type;
594 //
595 // Get the real part and use a generic_interconvert to type To:
596 //
597 scoped_precision_options<component_number> scope(from);
598 component_backend r;
599 generic_interconvert_complex_to_scalar(r, from, std::integral_constant<bool, true>(), std::integral_constant<bool, true>());
600 generic_interconvert(to, r, std::integral_constant<int, number_category<To>::value>(), std::integral_constant<int, number_category<component_backend>::value>());
601 }
602
603 template <class To, class From>
604 void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_floating_point>& /*to_type*/, const std::integral_constant<int, number_kind_complex>& /*from_type*/)
605 {
606 using component_number = typename component_type<number<From> >::type;
607 using component_backend = typename component_number::backend_type ;
608
609 generic_interconvert_complex_to_scalar(to, from, std::integral_constant<bool, std::is_same<component_backend, To>::value>(), std::integral_constant<bool, std::is_constructible<To, const component_backend&>::value>());
610 }
611 template <class To, class From>
612 void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_integer>& /*to_type*/, const std::integral_constant<int, number_kind_complex>& /*from_type*/)
613 {
614 using component_number = typename component_type<number<From> >::type;
615 using component_backend = typename component_number::backend_type ;
616
617 generic_interconvert_complex_to_scalar(to, from, std::integral_constant<bool, std::is_same<component_backend, To>::value>(), std::integral_constant<bool, std::is_constructible<To, const component_backend&>::value>());
618 }
619 template <class To, class From>
620 void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_rational>& /*to_type*/, const std::integral_constant<int, number_kind_complex>& /*from_type*/)
621 {
622 using component_number = typename component_type<number<From> >::type;
623 using component_backend = typename component_number::backend_type ;
624
625 generic_interconvert_complex_to_scalar(to, from, std::integral_constant<bool, std::is_same<component_backend, To>::value>(), std::integral_constant<bool, std::is_constructible<To, const component_backend&>::value>());
626 }
627 template <class To, class From>
628 void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_complex>& /*to_type*/, const std::integral_constant<int, number_kind_integer>& /*from_type*/)
629 {
630 using component_number = typename component_type<number<To> >::type;
631
632 scoped_source_precision<number<From> > scope1;
633 scoped_precision_options<component_number> scope2(number<To>::thread_default_precision(), number<To>::thread_default_variable_precision_options());
634 (void)scope1;
635 (void)scope2;
636
637 number<From> f(from);
638 component_number scalar(f);
639 number<To> result(scalar);
640 to = result.backend();
641 }
642 template <class To, class From>
643 void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_complex>& /*to_type*/, const std::integral_constant<int, number_kind_rational>& /*from_type*/)
644 {
645 using component_number = typename component_type<number<To> >::type;
646
647 scoped_source_precision<number<From> > scope1;
648 scoped_precision_options<component_number> scope2(number<To>::thread_default_precision(), number<To>::thread_default_variable_precision_options());
649 (void)scope1;
650 (void)scope2;
651
652 number<From> f(from);
653 component_number scalar(f);
654 number<To> result(scalar);
655 to = result.backend();
656 }
657 template <class To, class From>
658 void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_complex>& /*to_type*/, const std::integral_constant<int, number_kind_floating_point>& /*from_type*/)
659 {
660 using component_number = typename component_type<number<To> >::type;
661
662 scoped_source_precision<number<From> > scope1;
663 scoped_precision_options<component_number> scope2(number<To>::thread_default_precision(), number<To>::thread_default_variable_precision_options());
664 (void)scope1;
665 (void)scope2;
666
667 number<From> f(from);
668 component_number scalar(f);
669 number<To> result(scalar);
670 to = result.backend();
671 }
672 template <class To, class From, int Tag1, int Tag2>
673 void generic_interconvert(To& /*to*/, const From& /*from*/, const std::integral_constant<int, Tag1>& /*to_type*/, const std::integral_constant<int, Tag2>& /*from_type*/)
674 {
675 static_assert(sizeof(To) == 0, "Sorry, you asked for a conversion bewteen types that hasn't been implemented yet!!");
676 }
677
678 }
679 }
680 } // namespace boost::multiprecision::detail
681
682 #ifdef BOOST_MSVC
683 #pragma warning(pop)
684 #endif
685
686 #endif // BOOST_MP_GENERIC_INTERCONVERT_HPP