mpc.hpp 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright 2018 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_MULTIPRECISION_MPC_HPP
  6. #define BOOST_MULTIPRECISION_MPC_HPP
  7. #include <boost/multiprecision/number.hpp>
  8. #include <cstdint>
  9. #include <boost/multiprecision/detail/digits.hpp>
  10. #include <boost/multiprecision/detail/atomic.hpp>
  11. #include <boost/multiprecision/traits/is_variable_precision.hpp>
  12. #include <boost/multiprecision/mpfr.hpp>
  13. #include <boost/multiprecision/logged_adaptor.hpp>
  14. #include <boost/functional/hash_fwd.hpp>
  15. #include <mpc.h>
  16. #include <cmath>
  17. #include <algorithm>
  18. #include <complex>
  19. #ifndef BOOST_MULTIPRECISION_MPFI_DEFAULT_PRECISION
  20. #define BOOST_MULTIPRECISION_MPFI_DEFAULT_PRECISION 20
  21. #endif
  22. namespace boost {
  23. namespace multiprecision {
  24. namespace backends {
  25. template <unsigned digits10>
  26. struct mpc_complex_backend;
  27. } // namespace backends
  28. template <unsigned digits10>
  29. struct number_category<backends::mpc_complex_backend<digits10> > : public std::integral_constant<int, number_kind_complex>
  30. {};
  31. namespace backends {
  32. namespace detail {
  33. inline void mpc_copy_precision(mpc_t dest, const mpc_t src)
  34. {
  35. mpfr_prec_t p_dest = mpc_get_prec(dest);
  36. mpfr_prec_t p_src = mpc_get_prec(src);
  37. if (p_dest != p_src)
  38. mpc_set_prec(dest, p_src);
  39. }
  40. inline void mpc_copy_precision(mpc_t dest, const mpc_t src1, const mpc_t src2)
  41. {
  42. mpfr_prec_t p_dest = mpc_get_prec(dest);
  43. mpfr_prec_t p_src1 = mpc_get_prec(src1);
  44. mpfr_prec_t p_src2 = mpc_get_prec(src2);
  45. if (p_src2 > p_src1)
  46. p_src1 = p_src2;
  47. if (p_dest != p_src1)
  48. mpc_set_prec(dest, p_src1);
  49. }
  50. template <unsigned digits10>
  51. struct mpc_complex_imp
  52. {
  53. #ifdef BOOST_HAS_LONG_LONG
  54. using signed_types = std::tuple<long, boost::long_long_type> ;
  55. using unsigned_types = std::tuple<unsigned long, boost::ulong_long_type>;
  56. #else
  57. using signed_types = std::tuple<long> ;
  58. using unsigned_types = std::tuple<unsigned long>;
  59. #endif
  60. using float_types = std::tuple<double, long double>;
  61. using exponent_type = long ;
  62. mpc_complex_imp()
  63. {
  64. mpc_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  65. mpc_set_ui(m_data, 0u, GMP_RNDN);
  66. }
  67. mpc_complex_imp(unsigned digits2)
  68. {
  69. mpc_init2(m_data, digits2);
  70. mpc_set_ui(m_data, 0u, GMP_RNDN);
  71. }
  72. mpc_complex_imp(const mpc_complex_imp& o)
  73. {
  74. mpc_init2(m_data, mpc_get_prec(o.m_data));
  75. if (o.m_data[0].re[0]._mpfr_d)
  76. mpc_set(m_data, o.m_data, GMP_RNDN);
  77. }
  78. // rvalue copy
  79. mpc_complex_imp(mpc_complex_imp&& o) noexcept
  80. {
  81. m_data[0] = o.m_data[0];
  82. o.m_data[0].re[0]._mpfr_d = 0;
  83. }
  84. mpc_complex_imp& operator=(const mpc_complex_imp& o)
  85. {
  86. if ((o.m_data[0].re[0]._mpfr_d) && (this != &o))
  87. {
  88. if (m_data[0].re[0]._mpfr_d == 0)
  89. mpc_init2(m_data, mpc_get_prec(o.m_data));
  90. mpc_set(m_data, o.m_data, GMP_RNDD);
  91. }
  92. return *this;
  93. }
  94. // rvalue assign
  95. mpc_complex_imp& operator=(mpc_complex_imp&& o) noexcept
  96. {
  97. mpc_swap(m_data, o.m_data);
  98. return *this;
  99. }
  100. #ifdef BOOST_HAS_LONG_LONG
  101. #ifdef _MPFR_H_HAVE_INTMAX_T
  102. mpc_complex_imp& operator=(boost::ulong_long_type i)
  103. {
  104. if (m_data[0].re[0]._mpfr_d == 0)
  105. mpc_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  106. mpc_set_uj(data(), i, GMP_RNDD);
  107. return *this;
  108. }
  109. mpc_complex_imp& operator=(boost::long_long_type i)
  110. {
  111. if (m_data[0].re[0]._mpfr_d == 0)
  112. mpc_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  113. mpc_set_sj(data(), i, GMP_RNDD);
  114. return *this;
  115. }
  116. #else
  117. mpc_complex_imp& operator=(boost::ulong_long_type i)
  118. {
  119. mpfr_float_backend<digits10> f(0uL, mpc_get_prec(m_data));
  120. f = i;
  121. mpc_set_fr(this->data(), f.data(), GMP_RNDN);
  122. return *this;
  123. }
  124. mpc_complex_imp& operator=(boost::long_long_type i)
  125. {
  126. mpfr_float_backend<digits10> f(0uL, mpc_get_prec(m_data));
  127. f = i;
  128. mpc_set_fr(this->data(), f.data(), GMP_RNDN);
  129. return *this;
  130. }
  131. #endif
  132. #endif
  133. mpc_complex_imp& operator=(unsigned long i)
  134. {
  135. if (m_data[0].re[0]._mpfr_d == 0)
  136. mpc_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  137. mpc_set_ui(m_data, i, GMP_RNDN);
  138. return *this;
  139. }
  140. mpc_complex_imp& operator=(long i)
  141. {
  142. if (m_data[0].re[0]._mpfr_d == 0)
  143. mpc_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  144. mpc_set_si(m_data, i, GMP_RNDN);
  145. return *this;
  146. }
  147. mpc_complex_imp& operator=(double d)
  148. {
  149. if (m_data[0].re[0]._mpfr_d == 0)
  150. mpc_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  151. mpc_set_d(m_data, d, GMP_RNDN);
  152. return *this;
  153. }
  154. mpc_complex_imp& operator=(long double d)
  155. {
  156. if (m_data[0].re[0]._mpfr_d == 0)
  157. mpc_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  158. mpc_set_ld(m_data, d, GMP_RNDN);
  159. return *this;
  160. }
  161. mpc_complex_imp& operator=(mpz_t i)
  162. {
  163. if (m_data[0].re[0]._mpfr_d == 0)
  164. mpc_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  165. mpc_set_z(m_data, i, GMP_RNDN);
  166. return *this;
  167. }
  168. mpc_complex_imp& operator=(gmp_int i)
  169. {
  170. if (m_data[0].re[0]._mpfr_d == 0)
  171. mpc_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  172. mpc_set_z(m_data, i.data(), GMP_RNDN);
  173. return *this;
  174. }
  175. mpc_complex_imp& operator=(const char* s)
  176. {
  177. using default_ops::eval_fpclassify;
  178. if (m_data[0].re[0]._mpfr_d == 0)
  179. mpc_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  180. mpfr_float_backend<digits10> a(0uL, mpc_get_prec(m_data)), b(0uL, mpc_get_prec(m_data));
  181. if (s && (*s == '('))
  182. {
  183. std::string part;
  184. const char* p = ++s;
  185. while (*p && (*p != ',') && (*p != ')'))
  186. ++p;
  187. part.assign(s, p);
  188. if (part.size())
  189. a = part.c_str();
  190. else
  191. a = 0uL;
  192. s = p;
  193. if (*p && (*p != ')'))
  194. {
  195. ++p;
  196. while (*p && (*p != ')'))
  197. ++p;
  198. part.assign(s + 1, p);
  199. }
  200. else
  201. part.erase();
  202. if (part.size())
  203. b = part.c_str();
  204. else
  205. b = 0uL;
  206. }
  207. else
  208. {
  209. a = s;
  210. b = 0uL;
  211. }
  212. if (eval_fpclassify(a) == (int)FP_NAN)
  213. {
  214. mpc_set_fr(this->data(), a.data(), GMP_RNDN);
  215. }
  216. else if (eval_fpclassify(b) == (int)FP_NAN)
  217. {
  218. mpc_set_fr(this->data(), b.data(), GMP_RNDN);
  219. }
  220. else
  221. {
  222. mpc_set_fr_fr(m_data, a.data(), b.data(), GMP_RNDN);
  223. }
  224. return *this;
  225. }
  226. void swap(mpc_complex_imp& o) noexcept
  227. {
  228. mpc_swap(m_data, o.m_data);
  229. }
  230. std::string str(std::streamsize digits, std::ios_base::fmtflags f) const
  231. {
  232. BOOST_ASSERT(m_data[0].re[0]._mpfr_d);
  233. mpfr_float_backend<digits10> a(0uL, mpc_get_prec(m_data)), b(0uL, mpc_get_prec(m_data));
  234. mpc_real(a.data(), m_data, GMP_RNDD);
  235. mpc_imag(b.data(), m_data, GMP_RNDD);
  236. if (eval_is_zero(b))
  237. return a.str(digits, f);
  238. return "(" + a.str(digits, f) + "," + b.str(digits, f) + ")";
  239. }
  240. ~mpc_complex_imp() noexcept
  241. {
  242. if (m_data[0].re[0]._mpfr_d)
  243. mpc_clear(m_data);
  244. }
  245. void negate() noexcept
  246. {
  247. BOOST_ASSERT(m_data[0].re[0]._mpfr_d);
  248. mpc_neg(m_data, m_data, GMP_RNDD);
  249. }
  250. int compare(const mpc_complex_imp& o) const noexcept
  251. {
  252. BOOST_ASSERT(m_data[0].re[0]._mpfr_d && o.m_data[0].re[0]._mpfr_d);
  253. return mpc_cmp(m_data, o.m_data);
  254. }
  255. int compare(const mpc_complex_backend<digits10>& o) const noexcept
  256. {
  257. BOOST_ASSERT(m_data[0].re[0]._mpfr_d && o.m_data[0].re[0]._mpfr_d);
  258. return mpc_cmp(m_data, o.data());
  259. }
  260. int compare(long int i) const noexcept
  261. {
  262. BOOST_ASSERT(m_data[0].re[0]._mpfr_d);
  263. return mpc_cmp_si(m_data, i);
  264. }
  265. int compare(unsigned long int i) const noexcept
  266. {
  267. BOOST_ASSERT(m_data[0].re[0]._mpfr_d);
  268. constexpr const unsigned long int max_val = (std::numeric_limits<long>::max)();
  269. if (i > max_val)
  270. {
  271. mpc_complex_imp d(mpc_get_prec(m_data));
  272. d = i;
  273. return compare(d);
  274. }
  275. return mpc_cmp_si(m_data, (long)i);
  276. }
  277. template <class V>
  278. int compare(const V& v) const noexcept
  279. {
  280. mpc_complex_imp d(mpc_get_prec(m_data));
  281. d = v;
  282. return compare(d);
  283. }
  284. mpc_t& data() noexcept
  285. {
  286. BOOST_ASSERT(m_data[0].re[0]._mpfr_d);
  287. return m_data;
  288. }
  289. const mpc_t& data() const noexcept
  290. {
  291. BOOST_ASSERT(m_data[0].re[0]._mpfr_d);
  292. return m_data;
  293. }
  294. protected:
  295. mpc_t m_data;
  296. static boost::multiprecision::detail::precision_type& get_default_precision() noexcept
  297. {
  298. static boost::multiprecision::detail::precision_type val(BOOST_MULTIPRECISION_MPFI_DEFAULT_PRECISION);
  299. return val;
  300. }
  301. };
  302. } // namespace detail
  303. template <unsigned digits10>
  304. struct mpc_complex_backend : public detail::mpc_complex_imp<digits10>
  305. {
  306. mpc_complex_backend() : detail::mpc_complex_imp<digits10>() {}
  307. mpc_complex_backend(const mpc_complex_backend& o) : detail::mpc_complex_imp<digits10>(o) {}
  308. // rvalue copy
  309. mpc_complex_backend(mpc_complex_backend&& o) : detail::mpc_complex_imp<digits10>(static_cast<detail::mpc_complex_imp<digits10>&&>(o))
  310. {}
  311. template <unsigned D>
  312. mpc_complex_backend(const mpc_complex_backend<D>& val, typename std::enable_if<D <= digits10>::type* = 0)
  313. : detail::mpc_complex_imp<digits10>()
  314. {
  315. mpc_set(this->m_data, val.data(), GMP_RNDN);
  316. }
  317. template <unsigned D>
  318. explicit mpc_complex_backend(const mpc_complex_backend<D>& val, typename std::enable_if<!(D <= digits10)>::type* = 0)
  319. : detail::mpc_complex_imp<digits10>()
  320. {
  321. mpc_set(this->m_data, val.data(), GMP_RNDN);
  322. }
  323. template <unsigned D>
  324. mpc_complex_backend(const mpfr_float_backend<D>& val, typename std::enable_if<D <= digits10>::type* = 0)
  325. : detail::mpc_complex_imp<digits10>()
  326. {
  327. mpc_set_fr(this->m_data, val.data(), GMP_RNDN);
  328. }
  329. template <unsigned D>
  330. explicit mpc_complex_backend(const mpfr_float_backend<D>& val, typename std::enable_if<!(D <= digits10)>::type* = 0)
  331. : detail::mpc_complex_imp<digits10>()
  332. {
  333. mpc_set(this->m_data, val.data(), GMP_RNDN);
  334. }
  335. mpc_complex_backend(const mpc_t val)
  336. : detail::mpc_complex_imp<digits10>()
  337. {
  338. mpc_set(this->m_data, val, GMP_RNDN);
  339. }
  340. mpc_complex_backend(const std::complex<float>& val)
  341. : detail::mpc_complex_imp<digits10>()
  342. {
  343. mpc_set_d_d(this->m_data, val.real(), val.imag(), GMP_RNDN);
  344. }
  345. mpc_complex_backend(const std::complex<double>& val)
  346. : detail::mpc_complex_imp<digits10>()
  347. {
  348. mpc_set_d_d(this->m_data, val.real(), val.imag(), GMP_RNDN);
  349. }
  350. mpc_complex_backend(const std::complex<long double>& val)
  351. : detail::mpc_complex_imp<digits10>()
  352. {
  353. mpc_set_ld_ld(this->m_data, val.real(), val.imag(), GMP_RNDN);
  354. }
  355. mpc_complex_backend(mpz_srcptr val) : detail::mpc_complex_imp<digits10>()
  356. {
  357. mpc_set_z(this->m_data, val, GMP_RNDN);
  358. }
  359. mpc_complex_backend& operator=(mpz_srcptr val)
  360. {
  361. mpc_set_z(this->m_data, val, GMP_RNDN);
  362. return *this;
  363. }
  364. mpc_complex_backend(gmp_int const& val) : detail::mpc_complex_imp<digits10>()
  365. {
  366. mpc_set_z(this->m_data, val.data(), GMP_RNDN);
  367. }
  368. mpc_complex_backend& operator=(gmp_int const& val)
  369. {
  370. mpc_set_z(this->m_data, val.data(), GMP_RNDN);
  371. return *this;
  372. }
  373. mpc_complex_backend(mpf_srcptr val) : detail::mpc_complex_imp<digits10>()
  374. {
  375. mpc_set_f(this->m_data, val, GMP_RNDN);
  376. }
  377. mpc_complex_backend& operator=(mpf_srcptr val)
  378. {
  379. mpc_set_f(this->m_data, val, GMP_RNDN);
  380. return *this;
  381. }
  382. template <unsigned D10>
  383. mpc_complex_backend(gmp_float<D10> const& val) : detail::mpc_complex_imp<digits10>()
  384. {
  385. mpc_set_f(this->m_data, val.data(), GMP_RNDN);
  386. }
  387. template <unsigned D10>
  388. mpc_complex_backend& operator=(gmp_float<D10> const& val)
  389. {
  390. mpc_set_f(this->m_data, val.data(), GMP_RNDN);
  391. return *this;
  392. }
  393. mpc_complex_backend(mpq_srcptr val) : detail::mpc_complex_imp<digits10>()
  394. {
  395. mpc_set_q(this->m_data, val, GMP_RNDN);
  396. }
  397. mpc_complex_backend& operator=(mpq_srcptr val)
  398. {
  399. mpc_set_q(this->m_data, val, GMP_RNDN);
  400. return *this;
  401. }
  402. mpc_complex_backend(gmp_rational const& val) : detail::mpc_complex_imp<digits10>()
  403. {
  404. mpc_set_q(this->m_data, val.data(), GMP_RNDN);
  405. }
  406. mpc_complex_backend& operator=(gmp_rational const& val)
  407. {
  408. mpc_set_q(this->m_data, val.data(), GMP_RNDN);
  409. return *this;
  410. }
  411. mpc_complex_backend(mpfr_srcptr val) : detail::mpc_complex_imp<digits10>()
  412. {
  413. mpc_set_fr(this->m_data, val, GMP_RNDN);
  414. }
  415. mpc_complex_backend& operator=(mpfr_srcptr val)
  416. {
  417. mpc_set_fr(this->m_data, val, GMP_RNDN);
  418. return *this;
  419. }
  420. template <unsigned D10, mpfr_allocation_type AllocationType>
  421. mpc_complex_backend(mpfr_float_backend<D10, AllocationType> const& val) : detail::mpc_complex_imp<digits10>()
  422. {
  423. mpc_set_fr(this->m_data, val.data(), GMP_RNDN);
  424. }
  425. template <unsigned D10, mpfr_allocation_type AllocationType>
  426. mpc_complex_backend& operator=(mpfr_float_backend<D10, AllocationType> const& val)
  427. {
  428. mpc_set_fr(this->m_data, val.data(), GMP_RNDN);
  429. return *this;
  430. }
  431. mpc_complex_backend& operator=(const mpc_complex_backend& o)
  432. {
  433. *static_cast<detail::mpc_complex_imp<digits10>*>(this) = static_cast<detail::mpc_complex_imp<digits10> const&>(o);
  434. return *this;
  435. }
  436. // rvalue assign
  437. mpc_complex_backend& operator=(mpc_complex_backend&& o) noexcept
  438. {
  439. *static_cast<detail::mpc_complex_imp<digits10>*>(this) = static_cast<detail::mpc_complex_imp<digits10>&&>(o);
  440. return *this;
  441. }
  442. template <class V>
  443. mpc_complex_backend& operator=(const V& v)
  444. {
  445. *static_cast<detail::mpc_complex_imp<digits10>*>(this) = v;
  446. return *this;
  447. }
  448. mpc_complex_backend& operator=(const mpc_t val)
  449. {
  450. mpc_set(this->m_data, val, GMP_RNDN);
  451. return *this;
  452. }
  453. mpc_complex_backend& operator=(const std::complex<float>& val)
  454. {
  455. mpc_set_d_d(this->m_data, val.real(), val.imag(), GMP_RNDN);
  456. return *this;
  457. }
  458. mpc_complex_backend& operator=(const std::complex<double>& val)
  459. {
  460. mpc_set_d_d(this->m_data, val.real(), val.imag(), GMP_RNDN);
  461. return *this;
  462. }
  463. mpc_complex_backend& operator=(const std::complex<long double>& val)
  464. {
  465. mpc_set_ld_ld(this->m_data, val.real(), val.imag(), GMP_RNDN);
  466. return *this;
  467. }
  468. // We don't change our precision here, this is a fixed precision type:
  469. template <unsigned D>
  470. mpc_complex_backend& operator=(const mpc_complex_backend<D>& val)
  471. {
  472. mpc_set(this->m_data, val.data(), GMP_RNDN);
  473. return *this;
  474. }
  475. };
  476. template <>
  477. struct mpc_complex_backend<0> : public detail::mpc_complex_imp<0>
  478. {
  479. mpc_complex_backend() : detail::mpc_complex_imp<0>() {}
  480. mpc_complex_backend(const mpc_t val)
  481. : detail::mpc_complex_imp<0>(mpc_get_prec(val))
  482. {
  483. mpc_set(this->m_data, val, GMP_RNDN);
  484. }
  485. mpc_complex_backend(const mpc_complex_backend& o) : detail::mpc_complex_imp<0>(o) {}
  486. // rvalue copy
  487. mpc_complex_backend(mpc_complex_backend&& o) noexcept : detail::mpc_complex_imp<0>(static_cast<detail::mpc_complex_imp<0>&&>(o))
  488. {}
  489. mpc_complex_backend(const mpc_complex_backend& o, unsigned digits10)
  490. : detail::mpc_complex_imp<0>(multiprecision::detail::digits10_2_2(digits10))
  491. {
  492. mpc_set(this->m_data, o.data(), GMP_RNDN);
  493. }
  494. template <unsigned D>
  495. mpc_complex_backend(const mpc_complex_backend<D>& val)
  496. : detail::mpc_complex_imp<0>(mpc_get_prec(val.data()))
  497. {
  498. mpc_set(this->m_data, val.data(), GMP_RNDN);
  499. }
  500. template <unsigned D>
  501. mpc_complex_backend(const mpfr_float_backend<D>& val)
  502. : detail::mpc_complex_imp<0>(mpfr_get_prec(val.data()))
  503. {
  504. mpc_set_fr(this->m_data, val.data(), GMP_RNDN);
  505. }
  506. mpc_complex_backend(mpz_srcptr val) : detail::mpc_complex_imp<0>()
  507. {
  508. mpc_set_z(this->m_data, val, GMP_RNDN);
  509. }
  510. mpc_complex_backend& operator=(mpz_srcptr val)
  511. {
  512. mpc_set_z(this->m_data, val, GMP_RNDN);
  513. return *this;
  514. }
  515. mpc_complex_backend(gmp_int const& val) : detail::mpc_complex_imp<0>()
  516. {
  517. mpc_set_z(this->m_data, val.data(), GMP_RNDN);
  518. }
  519. mpc_complex_backend& operator=(gmp_int const& val)
  520. {
  521. mpc_set_z(this->m_data, val.data(), GMP_RNDN);
  522. return *this;
  523. }
  524. mpc_complex_backend(mpf_srcptr val) : detail::mpc_complex_imp<0>((unsigned)mpf_get_prec(val))
  525. {
  526. mpc_set_f(this->m_data, val, GMP_RNDN);
  527. }
  528. mpc_complex_backend& operator=(mpf_srcptr val)
  529. {
  530. if ((mp_bitcnt_t)mpc_get_prec(data()) != mpf_get_prec(val))
  531. {
  532. mpc_complex_backend t(val);
  533. t.swap(*this);
  534. }
  535. else
  536. mpc_set_f(this->m_data, val, GMP_RNDN);
  537. return *this;
  538. }
  539. template <unsigned digits10>
  540. mpc_complex_backend(gmp_float<digits10> const& val) : detail::mpc_complex_imp<0>((unsigned)mpf_get_prec(val.data()))
  541. {
  542. mpc_set_f(this->m_data, val.data(), GMP_RNDN);
  543. }
  544. template <unsigned digits10>
  545. mpc_complex_backend& operator=(gmp_float<digits10> const& val)
  546. {
  547. if (mpc_get_prec(data()) != (mpfr_prec_t)mpf_get_prec(val.data()))
  548. {
  549. mpc_complex_backend t(val);
  550. t.swap(*this);
  551. }
  552. else
  553. mpc_set_f(this->m_data, val.data(), GMP_RNDN);
  554. return *this;
  555. }
  556. mpc_complex_backend(mpq_srcptr val) : detail::mpc_complex_imp<0>()
  557. {
  558. mpc_set_q(this->m_data, val, GMP_RNDN);
  559. }
  560. mpc_complex_backend& operator=(mpq_srcptr val)
  561. {
  562. mpc_set_q(this->m_data, val, GMP_RNDN);
  563. return *this;
  564. }
  565. mpc_complex_backend(gmp_rational const& val) : detail::mpc_complex_imp<0>()
  566. {
  567. mpc_set_q(this->m_data, val.data(), GMP_RNDN);
  568. }
  569. mpc_complex_backend& operator=(gmp_rational const& val)
  570. {
  571. mpc_set_q(this->m_data, val.data(), GMP_RNDN);
  572. return *this;
  573. }
  574. mpc_complex_backend(mpfr_srcptr val) : detail::mpc_complex_imp<0>(mpfr_get_prec(val))
  575. {
  576. mpc_set_fr(this->m_data, val, GMP_RNDN);
  577. }
  578. mpc_complex_backend& operator=(mpfr_srcptr val)
  579. {
  580. if (mpc_get_prec(data()) != mpfr_get_prec(val))
  581. {
  582. mpc_complex_backend t(val);
  583. t.swap(*this);
  584. }
  585. else
  586. mpc_set_fr(this->m_data, val, GMP_RNDN);
  587. return *this;
  588. }
  589. mpc_complex_backend(const std::complex<float>& val)
  590. : detail::mpc_complex_imp<0>()
  591. {
  592. mpc_set_d_d(this->m_data, val.real(), val.imag(), GMP_RNDN);
  593. }
  594. mpc_complex_backend(const std::complex<double>& val)
  595. : detail::mpc_complex_imp<0>()
  596. {
  597. mpc_set_d_d(this->m_data, val.real(), val.imag(), GMP_RNDN);
  598. }
  599. mpc_complex_backend(const std::complex<long double>& val)
  600. : detail::mpc_complex_imp<0>()
  601. {
  602. mpc_set_ld_ld(this->m_data, val.real(), val.imag(), GMP_RNDN);
  603. }
  604. // Construction with precision:
  605. template <class T, class U>
  606. mpc_complex_backend(const T& a, const U& b, unsigned digits10)
  607. : detail::mpc_complex_imp<0>(multiprecision::detail::digits10_2_2(digits10))
  608. {
  609. // We can't use assign_components here because it copies the precision of
  610. // a and b, not digits10....
  611. mpfr_float ca(a), cb(b);
  612. mpc_set_fr_fr(this->data(), ca.backend().data(), cb.backend().data(), GMP_RNDN);
  613. }
  614. template <unsigned N>
  615. mpc_complex_backend(const mpfr_float_backend<N>& a, const mpfr_float_backend<N>& b, unsigned digits10)
  616. : detail::mpc_complex_imp<0>(multiprecision::detail::digits10_2_2(digits10))
  617. {
  618. mpc_set_fr_fr(this->data(), a.data(), b.data(), GMP_RNDN);
  619. }
  620. mpc_complex_backend& operator=(const mpc_complex_backend& o)
  621. {
  622. if (this != &o)
  623. {
  624. detail::mpc_copy_precision(this->m_data, o.data());
  625. mpc_set(this->m_data, o.data(), GMP_RNDN);
  626. }
  627. return *this;
  628. }
  629. // rvalue assign
  630. mpc_complex_backend& operator=(mpc_complex_backend&& o) noexcept
  631. {
  632. *static_cast<detail::mpc_complex_imp<0>*>(this) = static_cast<detail::mpc_complex_imp<0>&&>(o);
  633. return *this;
  634. }
  635. template <class V>
  636. mpc_complex_backend& operator=(const V& v)
  637. {
  638. *static_cast<detail::mpc_complex_imp<0>*>(this) = v;
  639. return *this;
  640. }
  641. mpc_complex_backend& operator=(const mpc_t val)
  642. {
  643. mpc_set_prec(this->m_data, mpc_get_prec(val));
  644. mpc_set(this->m_data, val, GMP_RNDN);
  645. return *this;
  646. }
  647. template <unsigned D>
  648. mpc_complex_backend& operator=(const mpc_complex_backend<D>& val)
  649. {
  650. mpc_set_prec(this->m_data, mpc_get_prec(val.data()));
  651. mpc_set(this->m_data, val.data(), GMP_RNDN);
  652. return *this;
  653. }
  654. template <unsigned D>
  655. mpc_complex_backend& operator=(const mpfr_float_backend<D>& val)
  656. {
  657. mpc_set_prec(this->m_data, mpfr_get_prec(val.data()));
  658. mpc_set_fr(this->m_data, val.data(), GMP_RNDN);
  659. return *this;
  660. }
  661. mpc_complex_backend& operator=(const std::complex<float>& val)
  662. {
  663. mpc_set_d_d(this->m_data, val.real(), val.imag(), GMP_RNDN);
  664. return *this;
  665. }
  666. mpc_complex_backend& operator=(const std::complex<double>& val)
  667. {
  668. mpc_set_d_d(this->m_data, val.real(), val.imag(), GMP_RNDN);
  669. return *this;
  670. }
  671. mpc_complex_backend& operator=(const std::complex<long double>& val)
  672. {
  673. mpc_set_ld_ld(this->m_data, val.real(), val.imag(), GMP_RNDN);
  674. return *this;
  675. }
  676. static unsigned default_precision() noexcept
  677. {
  678. return get_default_precision();
  679. }
  680. static void default_precision(unsigned v) noexcept
  681. {
  682. get_default_precision() = v;
  683. }
  684. unsigned precision() const noexcept
  685. {
  686. return multiprecision::detail::digits2_2_10(mpc_get_prec(this->m_data));
  687. }
  688. void precision(unsigned digits10) noexcept
  689. {
  690. mpfr_prec_round(mpc_realref(this->m_data), multiprecision::detail::digits10_2_2((digits10)), GMP_RNDN);
  691. mpfr_prec_round(mpc_imagref(this->m_data), multiprecision::detail::digits10_2_2((digits10)), GMP_RNDN);
  692. }
  693. };
  694. template <unsigned digits10, class T>
  695. inline typename std::enable_if<boost::multiprecision::detail::is_arithmetic<T>::value, bool>::type eval_eq(const mpc_complex_backend<digits10>& a, const T& b) noexcept
  696. {
  697. return a.compare(b) == 0;
  698. }
  699. template <unsigned digits10, class T>
  700. inline typename std::enable_if<boost::multiprecision::detail::is_arithmetic<T>::value, bool>::type eval_lt(const mpc_complex_backend<digits10>& a, const T& b) noexcept
  701. {
  702. return a.compare(b) < 0;
  703. }
  704. template <unsigned digits10, class T>
  705. inline typename std::enable_if<boost::multiprecision::detail::is_arithmetic<T>::value, bool>::type eval_gt(const mpc_complex_backend<digits10>& a, const T& b) noexcept
  706. {
  707. return a.compare(b) > 0;
  708. }
  709. template <unsigned D1, unsigned D2>
  710. inline void eval_add(mpc_complex_backend<D1>& result, const mpc_complex_backend<D2>& o)
  711. {
  712. mpc_add(result.data(), result.data(), o.data(), GMP_RNDD);
  713. }
  714. template <unsigned D1, unsigned D2>
  715. inline void eval_add(mpc_complex_backend<D1>& result, const mpfr_float_backend<D2>& o)
  716. {
  717. mpc_add_fr(result.data(), result.data(), o.data(), GMP_RNDD);
  718. }
  719. template <unsigned D1, unsigned D2>
  720. inline void eval_subtract(mpc_complex_backend<D1>& result, const mpc_complex_backend<D2>& o)
  721. {
  722. mpc_sub(result.data(), result.data(), o.data(), GMP_RNDD);
  723. }
  724. template <unsigned D1, unsigned D2>
  725. inline void eval_subtract(mpc_complex_backend<D1>& result, const mpfr_float_backend<D2>& o)
  726. {
  727. mpc_sub_fr(result.data(), result.data(), o.data(), GMP_RNDD);
  728. }
  729. template <unsigned D1, unsigned D2>
  730. inline void eval_multiply(mpc_complex_backend<D1>& result, const mpc_complex_backend<D2>& o)
  731. {
  732. if ((void*)&result == (void*)&o)
  733. mpc_sqr(result.data(), o.data(), GMP_RNDN);
  734. else
  735. mpc_mul(result.data(), result.data(), o.data(), GMP_RNDN);
  736. }
  737. template <unsigned D1, unsigned D2>
  738. inline void eval_multiply(mpc_complex_backend<D1>& result, const mpfr_float_backend<D2>& o)
  739. {
  740. mpc_mul_fr(result.data(), result.data(), o.data(), GMP_RNDN);
  741. }
  742. template <unsigned D1, unsigned D2>
  743. inline void eval_divide(mpc_complex_backend<D1>& result, const mpc_complex_backend<D2>& o)
  744. {
  745. mpc_div(result.data(), result.data(), o.data(), GMP_RNDD);
  746. }
  747. template <unsigned D1, unsigned D2>
  748. inline void eval_divide(mpc_complex_backend<D1>& result, const mpfr_float_backend<D2>& o)
  749. {
  750. mpc_div_fr(result.data(), result.data(), o.data(), GMP_RNDD);
  751. }
  752. template <unsigned digits10>
  753. inline void eval_add(mpc_complex_backend<digits10>& result, unsigned long i)
  754. {
  755. mpc_add_ui(result.data(), result.data(), i, GMP_RNDN);
  756. }
  757. template <unsigned digits10>
  758. inline void eval_subtract(mpc_complex_backend<digits10>& result, unsigned long i)
  759. {
  760. mpc_sub_ui(result.data(), result.data(), i, GMP_RNDN);
  761. }
  762. template <unsigned digits10>
  763. inline void eval_multiply(mpc_complex_backend<digits10>& result, unsigned long i)
  764. {
  765. mpc_mul_ui(result.data(), result.data(), i, GMP_RNDN);
  766. }
  767. template <unsigned digits10>
  768. inline void eval_divide(mpc_complex_backend<digits10>& result, unsigned long i)
  769. {
  770. mpc_div_ui(result.data(), result.data(), i, GMP_RNDN);
  771. }
  772. template <unsigned digits10>
  773. inline void eval_add(mpc_complex_backend<digits10>& result, long i)
  774. {
  775. if (i > 0)
  776. mpc_add_ui(result.data(), result.data(), i, GMP_RNDN);
  777. else
  778. mpc_sub_ui(result.data(), result.data(), boost::multiprecision::detail::unsigned_abs(i), GMP_RNDN);
  779. }
  780. template <unsigned digits10>
  781. inline void eval_subtract(mpc_complex_backend<digits10>& result, long i)
  782. {
  783. if (i > 0)
  784. mpc_sub_ui(result.data(), result.data(), i, GMP_RNDN);
  785. else
  786. mpc_add_ui(result.data(), result.data(), boost::multiprecision::detail::unsigned_abs(i), GMP_RNDN);
  787. }
  788. template <unsigned digits10>
  789. inline void eval_multiply(mpc_complex_backend<digits10>& result, long i)
  790. {
  791. mpc_mul_ui(result.data(), result.data(), boost::multiprecision::detail::unsigned_abs(i), GMP_RNDN);
  792. if (i < 0)
  793. mpc_neg(result.data(), result.data(), GMP_RNDN);
  794. }
  795. template <unsigned digits10>
  796. inline void eval_divide(mpc_complex_backend<digits10>& result, long i)
  797. {
  798. mpc_div_ui(result.data(), result.data(), boost::multiprecision::detail::unsigned_abs(i), GMP_RNDN);
  799. if (i < 0)
  800. mpc_neg(result.data(), result.data(), GMP_RNDN);
  801. }
  802. //
  803. // Specialised 3 arg versions of the basic operators:
  804. //
  805. template <unsigned D1, unsigned D2, unsigned D3>
  806. inline void eval_add(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, const mpc_complex_backend<D3>& y)
  807. {
  808. mpc_add(a.data(), x.data(), y.data(), GMP_RNDD);
  809. }
  810. template <unsigned D1, unsigned D2, unsigned D3>
  811. inline void eval_add(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, const mpfr_float_backend<D3>& y)
  812. {
  813. mpc_add_fr(a.data(), x.data(), y.data(), GMP_RNDD);
  814. }
  815. template <unsigned D1, unsigned D2, unsigned D3>
  816. inline void eval_add(mpc_complex_backend<D1>& a, const mpfr_float_backend<D2>& x, const mpc_complex_backend<D3>& y)
  817. {
  818. mpc_add_fr(a.data(), y.data(), x.data(), GMP_RNDD);
  819. }
  820. template <unsigned D1, unsigned D2>
  821. inline void eval_add(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, unsigned long y)
  822. {
  823. mpc_add_ui(a.data(), x.data(), y, GMP_RNDD);
  824. }
  825. template <unsigned D1, unsigned D2>
  826. inline void eval_add(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, long y)
  827. {
  828. if (y < 0)
  829. mpc_sub_ui(a.data(), x.data(), boost::multiprecision::detail::unsigned_abs(y), GMP_RNDD);
  830. else
  831. mpc_add_ui(a.data(), x.data(), y, GMP_RNDD);
  832. }
  833. template <unsigned D1, unsigned D2>
  834. inline void eval_add(mpc_complex_backend<D1>& a, unsigned long x, const mpc_complex_backend<D2>& y)
  835. {
  836. mpc_add_ui(a.data(), y.data(), x, GMP_RNDD);
  837. }
  838. template <unsigned D1, unsigned D2>
  839. inline void eval_add(mpc_complex_backend<D1>& a, long x, const mpc_complex_backend<D2>& y)
  840. {
  841. if (x < 0)
  842. {
  843. mpc_ui_sub(a.data(), boost::multiprecision::detail::unsigned_abs(x), y.data(), GMP_RNDN);
  844. mpc_neg(a.data(), a.data(), GMP_RNDD);
  845. }
  846. else
  847. mpc_add_ui(a.data(), y.data(), x, GMP_RNDD);
  848. }
  849. template <unsigned D1, unsigned D2, unsigned D3>
  850. inline void eval_subtract(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, const mpc_complex_backend<D3>& y)
  851. {
  852. mpc_sub(a.data(), x.data(), y.data(), GMP_RNDD);
  853. }
  854. template <unsigned D1, unsigned D2, unsigned D3>
  855. inline void eval_subtract(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, const mpfr_float_backend<D3>& y)
  856. {
  857. mpc_sub_fr(a.data(), x.data(), y.data(), GMP_RNDD);
  858. }
  859. template <unsigned D1, unsigned D2, unsigned D3>
  860. inline void eval_subtract(mpc_complex_backend<D1>& a, const mpfr_float_backend<D2>& x, const mpc_complex_backend<D3>& y)
  861. {
  862. mpc_fr_sub(a.data(), x.data(), y.data(), GMP_RNDD);
  863. }
  864. template <unsigned D1, unsigned D2>
  865. inline void eval_subtract(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, unsigned long y)
  866. {
  867. mpc_sub_ui(a.data(), x.data(), y, GMP_RNDD);
  868. }
  869. template <unsigned D1, unsigned D2>
  870. inline void eval_subtract(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, long y)
  871. {
  872. if (y < 0)
  873. mpc_add_ui(a.data(), x.data(), boost::multiprecision::detail::unsigned_abs(y), GMP_RNDD);
  874. else
  875. mpc_sub_ui(a.data(), x.data(), y, GMP_RNDD);
  876. }
  877. template <unsigned D1, unsigned D2>
  878. inline void eval_subtract(mpc_complex_backend<D1>& a, unsigned long x, const mpc_complex_backend<D2>& y)
  879. {
  880. mpc_ui_sub(a.data(), x, y.data(), GMP_RNDN);
  881. }
  882. template <unsigned D1, unsigned D2>
  883. inline void eval_subtract(mpc_complex_backend<D1>& a, long x, const mpc_complex_backend<D2>& y)
  884. {
  885. if (x < 0)
  886. {
  887. mpc_add_ui(a.data(), y.data(), boost::multiprecision::detail::unsigned_abs(x), GMP_RNDD);
  888. mpc_neg(a.data(), a.data(), GMP_RNDD);
  889. }
  890. else
  891. mpc_ui_sub(a.data(), x, y.data(), GMP_RNDN);
  892. }
  893. template <unsigned D1, unsigned D2, unsigned D3>
  894. inline void eval_multiply(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, const mpc_complex_backend<D3>& y)
  895. {
  896. if ((void*)&x == (void*)&y)
  897. mpc_sqr(a.data(), x.data(), GMP_RNDD);
  898. else
  899. mpc_mul(a.data(), x.data(), y.data(), GMP_RNDD);
  900. }
  901. template <unsigned D1, unsigned D2, unsigned D3>
  902. inline void eval_multiply(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, const mpfr_float_backend<D3>& y)
  903. {
  904. mpc_mul_fr(a.data(), x.data(), y.data(), GMP_RNDD);
  905. }
  906. template <unsigned D1, unsigned D2, unsigned D3>
  907. inline void eval_multiply(mpc_complex_backend<D1>& a, const mpfr_float_backend<D2>& x, const mpc_complex_backend<D3>& y)
  908. {
  909. mpc_mul_fr(a.data(), y.data(), x.data(), GMP_RNDD);
  910. }
  911. template <unsigned D1, unsigned D2>
  912. inline void eval_multiply(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, unsigned long y)
  913. {
  914. mpc_mul_ui(a.data(), x.data(), y, GMP_RNDD);
  915. }
  916. template <unsigned D1, unsigned D2>
  917. inline void eval_multiply(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, long y)
  918. {
  919. if (y < 0)
  920. {
  921. mpc_mul_ui(a.data(), x.data(), boost::multiprecision::detail::unsigned_abs(y), GMP_RNDD);
  922. a.negate();
  923. }
  924. else
  925. mpc_mul_ui(a.data(), x.data(), y, GMP_RNDD);
  926. }
  927. template <unsigned D1, unsigned D2>
  928. inline void eval_multiply(mpc_complex_backend<D1>& a, unsigned long x, const mpc_complex_backend<D2>& y)
  929. {
  930. mpc_mul_ui(a.data(), y.data(), x, GMP_RNDD);
  931. }
  932. template <unsigned D1, unsigned D2>
  933. inline void eval_multiply(mpc_complex_backend<D1>& a, long x, const mpc_complex_backend<D2>& y)
  934. {
  935. if (x < 0)
  936. {
  937. mpc_mul_ui(a.data(), y.data(), boost::multiprecision::detail::unsigned_abs(x), GMP_RNDD);
  938. mpc_neg(a.data(), a.data(), GMP_RNDD);
  939. }
  940. else
  941. mpc_mul_ui(a.data(), y.data(), x, GMP_RNDD);
  942. }
  943. template <unsigned D1, unsigned D2, unsigned D3>
  944. inline void eval_divide(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, const mpc_complex_backend<D3>& y)
  945. {
  946. mpc_div(a.data(), x.data(), y.data(), GMP_RNDD);
  947. }
  948. template <unsigned D1, unsigned D2, unsigned D3>
  949. inline void eval_divide(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, const mpfr_float_backend<D3>& y)
  950. {
  951. mpc_div_fr(a.data(), x.data(), y.data(), GMP_RNDD);
  952. }
  953. template <unsigned D1, unsigned D2, unsigned D3>
  954. inline void eval_divide(mpc_complex_backend<D1>& a, const mpfr_float_backend<D2>& x, const mpc_complex_backend<D3>& y)
  955. {
  956. mpc_fr_div(a.data(), x.data(), y.data(), GMP_RNDD);
  957. }
  958. template <unsigned D1, unsigned D2>
  959. inline void eval_divide(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, unsigned long y)
  960. {
  961. mpc_div_ui(a.data(), x.data(), y, GMP_RNDD);
  962. }
  963. template <unsigned D1, unsigned D2>
  964. inline void eval_divide(mpc_complex_backend<D1>& a, const mpc_complex_backend<D2>& x, long y)
  965. {
  966. if (y < 0)
  967. {
  968. mpc_div_ui(a.data(), x.data(), boost::multiprecision::detail::unsigned_abs(y), GMP_RNDD);
  969. a.negate();
  970. }
  971. else
  972. mpc_div_ui(a.data(), x.data(), y, GMP_RNDD);
  973. }
  974. template <unsigned D1, unsigned D2>
  975. inline void eval_divide(mpc_complex_backend<D1>& a, unsigned long x, const mpc_complex_backend<D2>& y)
  976. {
  977. mpc_ui_div(a.data(), x, y.data(), GMP_RNDD);
  978. }
  979. template <unsigned D1, unsigned D2>
  980. inline void eval_divide(mpc_complex_backend<D1>& a, long x, const mpc_complex_backend<D2>& y)
  981. {
  982. if (x < 0)
  983. {
  984. mpc_ui_div(a.data(), boost::multiprecision::detail::unsigned_abs(x), y.data(), GMP_RNDD);
  985. mpc_neg(a.data(), a.data(), GMP_RNDD);
  986. }
  987. else
  988. mpc_ui_div(a.data(), x, y.data(), GMP_RNDD);
  989. }
  990. template <unsigned digits10>
  991. inline bool eval_is_zero(const mpc_complex_backend<digits10>& val) noexcept
  992. {
  993. return (0 != mpfr_zero_p(mpc_realref(val.data()))) && (0 != mpfr_zero_p(mpc_imagref(val.data())));
  994. }
  995. template <unsigned digits10>
  996. inline int eval_get_sign(const mpc_complex_backend<digits10>&)
  997. {
  998. static_assert(digits10 == UINT_MAX, "Complex numbers have no sign bit."); // designed to always fail
  999. return 0;
  1000. }
  1001. template <unsigned digits10>
  1002. inline void eval_convert_to(unsigned long* result, const mpc_complex_backend<digits10>& val)
  1003. {
  1004. if (0 == mpfr_zero_p(mpc_imagref(val.data())))
  1005. {
  1006. BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert imaginary number to scalar."));
  1007. }
  1008. mpfr_float_backend<digits10> t;
  1009. mpc_real(t.data(), val.data(), GMP_RNDN);
  1010. eval_convert_to(result, t);
  1011. }
  1012. template <unsigned digits10>
  1013. inline void eval_convert_to(long* result, const mpc_complex_backend<digits10>& val)
  1014. {
  1015. if (0 == mpfr_zero_p(mpc_imagref(val.data())))
  1016. {
  1017. BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert imaginary number to scalar."));
  1018. }
  1019. mpfr_float_backend<digits10> t;
  1020. mpc_real(t.data(), val.data(), GMP_RNDN);
  1021. eval_convert_to(result, t);
  1022. }
  1023. #ifdef _MPFR_H_HAVE_INTMAX_T
  1024. template <unsigned digits10>
  1025. inline void eval_convert_to(boost::ulong_long_type* result, const mpc_complex_backend<digits10>& val)
  1026. {
  1027. if (0 == mpfr_zero_p(mpc_imagref(val.data())))
  1028. {
  1029. BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert imaginary number to scalar."));
  1030. }
  1031. mpfr_float_backend<digits10> t;
  1032. mpc_real(t.data(), val.data(), GMP_RNDN);
  1033. eval_convert_to(result, t);
  1034. }
  1035. template <unsigned digits10>
  1036. inline void eval_convert_to(boost::long_long_type* result, const mpc_complex_backend<digits10>& val)
  1037. {
  1038. if (0 == mpfr_zero_p(mpc_imagref(val.data())))
  1039. {
  1040. BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert imaginary number to scalar."));
  1041. }
  1042. mpfr_float_backend<digits10> t;
  1043. mpc_real(t.data(), val.data(), GMP_RNDN);
  1044. eval_convert_to(result, t);
  1045. }
  1046. #endif
  1047. template <unsigned digits10>
  1048. inline void eval_convert_to(double* result, const mpc_complex_backend<digits10>& val) noexcept
  1049. {
  1050. if (0 == mpfr_zero_p(mpc_imagref(val.data())))
  1051. {
  1052. BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert imaginary number to scalar."));
  1053. }
  1054. mpfr_float_backend<digits10> t;
  1055. mpc_real(t.data(), val.data(), GMP_RNDN);
  1056. eval_convert_to(result, t);
  1057. }
  1058. template <unsigned digits10>
  1059. inline void eval_convert_to(long double* result, const mpc_complex_backend<digits10>& val) noexcept
  1060. {
  1061. if (0 == mpfr_zero_p(mpc_imagref(val.data())))
  1062. {
  1063. BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert imaginary number to scalar."));
  1064. }
  1065. mpfr_float_backend<digits10> t;
  1066. mpc_real(t.data(), val.data(), GMP_RNDN);
  1067. eval_convert_to(result, t);
  1068. }
  1069. template <unsigned D1, unsigned D2, mpfr_allocation_type AllocationType>
  1070. inline void assign_components(mpc_complex_backend<D1>& result, const mpfr_float_backend<D2, AllocationType>& a, const mpfr_float_backend<D2, AllocationType>& b)
  1071. {
  1072. //
  1073. // This is called from class number's constructors, so if we have variable
  1074. // precision, then copy the precision of the source variables.
  1075. //
  1076. if (!D1)
  1077. {
  1078. unsigned long prec = (std::max)(mpfr_get_prec(a.data()), mpfr_get_prec(b.data()));
  1079. mpc_set_prec(result.data(), prec);
  1080. }
  1081. using default_ops::eval_fpclassify;
  1082. if (eval_fpclassify(a) == (int)FP_NAN)
  1083. {
  1084. mpc_set_fr(result.data(), a.data(), GMP_RNDN);
  1085. }
  1086. else if (eval_fpclassify(b) == (int)FP_NAN)
  1087. {
  1088. mpc_set_fr(result.data(), b.data(), GMP_RNDN);
  1089. }
  1090. else
  1091. {
  1092. mpc_set_fr_fr(result.data(), a.data(), b.data(), GMP_RNDN);
  1093. }
  1094. }
  1095. template <unsigned D1, unsigned D2, mpfr_allocation_type AllocationType>
  1096. inline void assign_components(mpc_complex_backend<D1>& result, unsigned long a, unsigned long b)
  1097. {
  1098. mpc_set_ui_ui(result.data(), a, b, GMP_RNDN);
  1099. }
  1100. template <unsigned D1, unsigned D2, mpfr_allocation_type AllocationType>
  1101. inline void assign_components(mpc_complex_backend<D1>& result, long a, long b)
  1102. {
  1103. mpc_set_si_si(result.data(), a, b, GMP_RNDN);
  1104. }
  1105. #if defined(BOOST_HAS_LONG_LONG) && defined(_MPFR_H_HAVE_INTMAX_T)
  1106. template <unsigned D1, unsigned D2, mpfr_allocation_type AllocationType>
  1107. inline void assign_components(mpc_complex_backend<D1>& result, unsigned long long a, unsigned long long b)
  1108. {
  1109. mpc_set_uj_uj(result.data(), a, b, GMP_RNDN);
  1110. }
  1111. template <unsigned D1, unsigned D2, mpfr_allocation_type AllocationType>
  1112. inline void assign_components(mpc_complex_backend<D1>& result, long long a, long long b)
  1113. {
  1114. mpc_set_sj_sj(result.data(), a, b, GMP_RNDN);
  1115. }
  1116. #endif
  1117. template <unsigned D1, unsigned D2, mpfr_allocation_type AllocationType>
  1118. inline void assign_components(mpc_complex_backend<D1>& result, double a, double b)
  1119. {
  1120. if ((boost::math::isnan)(a))
  1121. {
  1122. mpc_set_d(result.data(), a, GMP_RNDN);
  1123. }
  1124. else if ((boost::math::isnan)(b))
  1125. {
  1126. mpc_set_d(result.data(), b, GMP_RNDN);
  1127. }
  1128. else
  1129. {
  1130. mpc_set_d_d(result.data(), a, b, GMP_RNDN);
  1131. }
  1132. }
  1133. template <unsigned D1, unsigned D2, mpfr_allocation_type AllocationType>
  1134. inline void assign_components(mpc_complex_backend<D1>& result, long double a, long double b)
  1135. {
  1136. if ((boost::math::isnan)(a))
  1137. {
  1138. mpc_set_d(result.data(), a, GMP_RNDN);
  1139. }
  1140. else if ((boost::math::isnan)(b))
  1141. {
  1142. mpc_set_d(result.data(), b, GMP_RNDN);
  1143. }
  1144. else
  1145. {
  1146. mpc_set_ld_ld(result.data(), a, b, GMP_RNDN);
  1147. }
  1148. }
  1149. //
  1150. // Native non-member operations:
  1151. //
  1152. template <unsigned Digits10>
  1153. inline void eval_sqrt(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& val)
  1154. {
  1155. mpc_sqrt(result.data(), val.data(), GMP_RNDN);
  1156. }
  1157. template <unsigned Digits10>
  1158. inline void eval_pow(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& b, const mpc_complex_backend<Digits10>& e)
  1159. {
  1160. mpc_pow(result.data(), b.data(), e.data(), GMP_RNDN);
  1161. }
  1162. template <unsigned Digits10>
  1163. inline void eval_exp(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1164. {
  1165. mpc_exp(result.data(), arg.data(), GMP_RNDN);
  1166. }
  1167. template <unsigned Digits10>
  1168. inline void eval_log(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1169. {
  1170. mpc_log(result.data(), arg.data(), GMP_RNDN);
  1171. }
  1172. template <unsigned Digits10>
  1173. inline void eval_log10(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1174. {
  1175. mpc_log10(result.data(), arg.data(), GMP_RNDN);
  1176. }
  1177. template <unsigned Digits10>
  1178. inline void eval_sin(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1179. {
  1180. mpc_sin(result.data(), arg.data(), GMP_RNDN);
  1181. }
  1182. template <unsigned Digits10>
  1183. inline void eval_cos(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1184. {
  1185. mpc_cos(result.data(), arg.data(), GMP_RNDN);
  1186. }
  1187. template <unsigned Digits10>
  1188. inline void eval_tan(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1189. {
  1190. mpc_tan(result.data(), arg.data(), GMP_RNDN);
  1191. }
  1192. template <unsigned Digits10>
  1193. inline void eval_asin(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1194. {
  1195. mpc_asin(result.data(), arg.data(), GMP_RNDN);
  1196. }
  1197. template <unsigned Digits10>
  1198. inline void eval_acos(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1199. {
  1200. mpc_acos(result.data(), arg.data(), GMP_RNDN);
  1201. }
  1202. template <unsigned Digits10>
  1203. inline void eval_atan(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1204. {
  1205. mpc_atan(result.data(), arg.data(), GMP_RNDN);
  1206. }
  1207. template <unsigned Digits10>
  1208. inline void eval_sinh(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1209. {
  1210. mpc_sinh(result.data(), arg.data(), GMP_RNDN);
  1211. }
  1212. template <unsigned Digits10>
  1213. inline void eval_cosh(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1214. {
  1215. mpc_cosh(result.data(), arg.data(), GMP_RNDN);
  1216. }
  1217. template <unsigned Digits10>
  1218. inline void eval_tanh(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1219. {
  1220. mpc_tanh(result.data(), arg.data(), GMP_RNDN);
  1221. }
  1222. template <unsigned Digits10>
  1223. inline void eval_asinh(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1224. {
  1225. mpc_asinh(result.data(), arg.data(), GMP_RNDN);
  1226. }
  1227. template <unsigned Digits10>
  1228. inline void eval_acosh(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1229. {
  1230. mpc_acosh(result.data(), arg.data(), GMP_RNDN);
  1231. }
  1232. template <unsigned Digits10>
  1233. inline void eval_atanh(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1234. {
  1235. mpc_atanh(result.data(), arg.data(), GMP_RNDN);
  1236. }
  1237. template <unsigned Digits10>
  1238. inline void eval_conj(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1239. {
  1240. mpc_conj(result.data(), arg.data(), GMP_RNDN);
  1241. }
  1242. template <unsigned Digits10>
  1243. inline void eval_proj(mpc_complex_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1244. {
  1245. mpc_proj(result.data(), arg.data(), GMP_RNDN);
  1246. }
  1247. template <unsigned Digits10>
  1248. inline void eval_real(mpfr_float_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1249. {
  1250. mpfr_set_prec(result.data(), mpfr_get_prec(mpc_realref(arg.data())));
  1251. mpfr_set(result.data(), mpc_realref(arg.data()), GMP_RNDN);
  1252. }
  1253. template <unsigned Digits10>
  1254. inline void eval_imag(mpfr_float_backend<Digits10>& result, const mpc_complex_backend<Digits10>& arg)
  1255. {
  1256. mpfr_set_prec(result.data(), mpfr_get_prec(mpc_imagref(arg.data())));
  1257. mpfr_set(result.data(), mpc_imagref(arg.data()), GMP_RNDN);
  1258. }
  1259. template <unsigned Digits10>
  1260. inline void eval_set_imag(mpc_complex_backend<Digits10>& result, const mpfr_float_backend<Digits10>& arg)
  1261. {
  1262. mpfr_set(mpc_imagref(result.data()), arg.data(), GMP_RNDN);
  1263. }
  1264. template <unsigned Digits10>
  1265. inline void eval_set_real(mpc_complex_backend<Digits10>& result, const mpfr_float_backend<Digits10>& arg)
  1266. {
  1267. mpfr_set(mpc_realref(result.data()), arg.data(), GMP_RNDN);
  1268. }
  1269. template <unsigned Digits10>
  1270. inline void eval_set_real(mpc_complex_backend<Digits10>& result, const gmp_int& arg)
  1271. {
  1272. mpfr_set_z(mpc_realref(result.data()), arg.data(), GMP_RNDN);
  1273. }
  1274. template <unsigned Digits10>
  1275. inline void eval_set_real(mpc_complex_backend<Digits10>& result, const gmp_rational& arg)
  1276. {
  1277. mpfr_set_q(mpc_realref(result.data()), arg.data(), GMP_RNDN);
  1278. }
  1279. template <unsigned Digits10>
  1280. inline void eval_set_real(mpc_complex_backend<Digits10>& result, const unsigned& arg)
  1281. {
  1282. mpfr_set_ui(mpc_realref(result.data()), arg, GMP_RNDN);
  1283. }
  1284. template <unsigned Digits10>
  1285. inline void eval_set_real(mpc_complex_backend<Digits10>& result, const unsigned long& arg)
  1286. {
  1287. mpfr_set_ui(mpc_realref(result.data()), arg, GMP_RNDN);
  1288. }
  1289. template <unsigned Digits10>
  1290. inline void eval_set_real(mpc_complex_backend<Digits10>& result, const int& arg)
  1291. {
  1292. mpfr_set_si(mpc_realref(result.data()), arg, GMP_RNDN);
  1293. }
  1294. template <unsigned Digits10>
  1295. inline void eval_set_real(mpc_complex_backend<Digits10>& result, const long& arg)
  1296. {
  1297. mpfr_set_si(mpc_realref(result.data()), arg, GMP_RNDN);
  1298. }
  1299. template <unsigned Digits10>
  1300. inline void eval_set_real(mpc_complex_backend<Digits10>& result, const float& arg)
  1301. {
  1302. mpfr_set_flt(mpc_realref(result.data()), arg, GMP_RNDN);
  1303. }
  1304. template <unsigned Digits10>
  1305. inline void eval_set_real(mpc_complex_backend<Digits10>& result, const double& arg)
  1306. {
  1307. mpfr_set_d(mpc_realref(result.data()), arg, GMP_RNDN);
  1308. }
  1309. template <unsigned Digits10>
  1310. inline void eval_set_real(mpc_complex_backend<Digits10>& result, const long double& arg)
  1311. {
  1312. mpfr_set_ld(mpc_realref(result.data()), arg, GMP_RNDN);
  1313. }
  1314. #if defined(BOOST_HAS_LONG_LONG) && defined(_MPFR_H_HAVE_INTMAX_T)
  1315. template <unsigned Digits10>
  1316. inline void eval_set_real(mpc_complex_backend<Digits10>& result, const unsigned long long& arg)
  1317. {
  1318. mpfr_set_uj(mpc_realref(result.data()), arg, GMP_RNDN);
  1319. }
  1320. template <unsigned Digits10>
  1321. inline void eval_set_real(mpc_complex_backend<Digits10>& result, const long long& arg)
  1322. {
  1323. mpfr_set_sj(mpc_realref(result.data()), arg, GMP_RNDN);
  1324. }
  1325. #endif
  1326. template <unsigned Digits10>
  1327. inline void eval_set_imag(mpc_complex_backend<Digits10>& result, const gmp_int& arg)
  1328. {
  1329. mpfr_set_z(mpc_imagref(result.data()), arg.data(), GMP_RNDN);
  1330. }
  1331. template <unsigned Digits10>
  1332. inline void eval_set_imag(mpc_complex_backend<Digits10>& result, const gmp_rational& arg)
  1333. {
  1334. mpfr_set_q(mpc_imagref(result.data()), arg.data(), GMP_RNDN);
  1335. }
  1336. template <unsigned Digits10>
  1337. inline void eval_set_imag(mpc_complex_backend<Digits10>& result, const unsigned& arg)
  1338. {
  1339. mpfr_set_ui(mpc_imagref(result.data()), arg, GMP_RNDN);
  1340. }
  1341. template <unsigned Digits10>
  1342. inline void eval_set_imag(mpc_complex_backend<Digits10>& result, const unsigned long& arg)
  1343. {
  1344. mpfr_set_ui(mpc_imagref(result.data()), arg, GMP_RNDN);
  1345. }
  1346. template <unsigned Digits10>
  1347. inline void eval_set_imag(mpc_complex_backend<Digits10>& result, const int& arg)
  1348. {
  1349. mpfr_set_si(mpc_imagref(result.data()), arg, GMP_RNDN);
  1350. }
  1351. template <unsigned Digits10>
  1352. inline void eval_set_imag(mpc_complex_backend<Digits10>& result, const long& arg)
  1353. {
  1354. mpfr_set_si(mpc_imagref(result.data()), arg, GMP_RNDN);
  1355. }
  1356. template <unsigned Digits10>
  1357. inline void eval_set_imag(mpc_complex_backend<Digits10>& result, const float& arg)
  1358. {
  1359. mpfr_set_flt(mpc_imagref(result.data()), arg, GMP_RNDN);
  1360. }
  1361. template <unsigned Digits10>
  1362. inline void eval_set_imag(mpc_complex_backend<Digits10>& result, const double& arg)
  1363. {
  1364. mpfr_set_d(mpc_imagref(result.data()), arg, GMP_RNDN);
  1365. }
  1366. template <unsigned Digits10>
  1367. inline void eval_set_imag(mpc_complex_backend<Digits10>& result, const long double& arg)
  1368. {
  1369. mpfr_set_ld(mpc_imagref(result.data()), arg, GMP_RNDN);
  1370. }
  1371. #if defined(BOOST_HAS_LONG_LONG) && defined(_MPFR_H_HAVE_INTMAX_T)
  1372. template <unsigned Digits10>
  1373. inline void eval_set_imag(mpc_complex_backend<Digits10>& result, const unsigned long long& arg)
  1374. {
  1375. mpfr_set_uj(mpc_imagref(result.data()), arg, GMP_RNDN);
  1376. }
  1377. template <unsigned Digits10>
  1378. inline void eval_set_imag(mpc_complex_backend<Digits10>& result, const long long& arg)
  1379. {
  1380. mpfr_set_sj(mpc_imagref(result.data()), arg, GMP_RNDN);
  1381. }
  1382. #endif
  1383. template <unsigned Digits10>
  1384. inline std::size_t hash_value(const mpc_complex_backend<Digits10>& val)
  1385. {
  1386. std::size_t result = 0;
  1387. std::size_t len = val.data()[0].re[0]._mpfr_prec / mp_bits_per_limb;
  1388. if (val.data()[0].re[0]._mpfr_prec % mp_bits_per_limb)
  1389. ++len;
  1390. for (std::size_t i = 0; i < len; ++i)
  1391. boost::hash_combine(result, val.data()[0].re[0]._mpfr_d[i]);
  1392. boost::hash_combine(result, val.data()[0].re[0]._mpfr_exp);
  1393. boost::hash_combine(result, val.data()[0].re[0]._mpfr_sign);
  1394. len = val.data()[0].im[0]._mpfr_prec / mp_bits_per_limb;
  1395. if (val.data()[0].im[0]._mpfr_prec % mp_bits_per_limb)
  1396. ++len;
  1397. for (std::size_t i = 0; i < len; ++i)
  1398. boost::hash_combine(result, val.data()[0].im[0]._mpfr_d[i]);
  1399. boost::hash_combine(result, val.data()[0].im[0]._mpfr_exp);
  1400. boost::hash_combine(result, val.data()[0].im[0]._mpfr_sign);
  1401. return result;
  1402. }
  1403. } // namespace backends
  1404. namespace detail {
  1405. template <>
  1406. struct is_variable_precision<backends::mpc_complex_backend<0> > : public std::integral_constant<bool, true>
  1407. {};
  1408. } // namespace detail
  1409. template <>
  1410. struct number_category<detail::canonical<mpc_t, backends::mpc_complex_backend<0> >::type> : public std::integral_constant<int, number_kind_floating_point>
  1411. {};
  1412. using boost::multiprecision::backends::mpc_complex_backend;
  1413. using mpc_complex_50 = number<mpc_complex_backend<50> > ;
  1414. using mpc_complex_100 = number<mpc_complex_backend<100> > ;
  1415. using mpc_complex_500 = number<mpc_complex_backend<500> > ;
  1416. using mpc_complex_1000 = number<mpc_complex_backend<1000> >;
  1417. using mpc_complex = number<mpc_complex_backend<0> > ;
  1418. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  1419. struct component_type<number<mpc_complex_backend<Digits10>, ExpressionTemplates> >
  1420. {
  1421. using type = number<mpfr_float_backend<Digits10>, ExpressionTemplates>;
  1422. };
  1423. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  1424. struct component_type<number<logged_adaptor<mpc_complex_backend<Digits10> >, ExpressionTemplates> >
  1425. {
  1426. using type = number<mpfr_float_backend<Digits10>, ExpressionTemplates>;
  1427. };
  1428. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  1429. struct complex_result_from_scalar<number<mpfr_float_backend<Digits10>, ExpressionTemplates> >
  1430. {
  1431. using type = number<mpc_complex_backend<Digits10>, ExpressionTemplates>;
  1432. };
  1433. }
  1434. } // namespace boost::multiprecision
  1435. #endif