generic_interconvert.hpp 22 KB

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