mpfr.hpp 125 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632
  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_MATH_BN_MPFR_HPP
  6. #define BOOST_MATH_BN_MPFR_HPP
  7. #include <boost/multiprecision/number.hpp>
  8. #include <boost/multiprecision/debug_adaptor.hpp>
  9. #include <boost/multiprecision/gmp.hpp>
  10. #include <boost/math/special_functions/fpclassify.hpp>
  11. #include <boost/cstdint.hpp>
  12. #include <boost/multiprecision/detail/big_lanczos.hpp>
  13. #include <boost/multiprecision/detail/digits.hpp>
  14. #include <boost/multiprecision/detail/atomic.hpp>
  15. #include <mpfr.h>
  16. #include <cmath>
  17. #include <algorithm>
  18. #ifndef BOOST_MULTIPRECISION_MPFR_DEFAULT_PRECISION
  19. #define BOOST_MULTIPRECISION_MPFR_DEFAULT_PRECISION 20
  20. #endif
  21. namespace boost {
  22. namespace multiprecision {
  23. enum mpfr_allocation_type
  24. {
  25. allocate_stack,
  26. allocate_dynamic
  27. };
  28. namespace backends {
  29. template <unsigned digits10, mpfr_allocation_type AllocationType = allocate_dynamic>
  30. struct mpfr_float_backend;
  31. template <>
  32. struct mpfr_float_backend<0, allocate_stack>;
  33. } // namespace backends
  34. template <unsigned digits10, mpfr_allocation_type AllocationType>
  35. struct number_category<backends::mpfr_float_backend<digits10, AllocationType> > : public mpl::int_<number_kind_floating_point>
  36. {};
  37. namespace backends {
  38. namespace detail {
  39. template <bool b>
  40. struct mpfr_cleanup
  41. {
  42. struct initializer
  43. {
  44. initializer() {}
  45. ~initializer() { mpfr_free_cache(); }
  46. void force_instantiate() const {}
  47. };
  48. static const initializer init;
  49. static void force_instantiate() { init.force_instantiate(); }
  50. };
  51. template <bool b>
  52. typename mpfr_cleanup<b>::initializer const mpfr_cleanup<b>::init;
  53. inline void mpfr_copy_precision(mpfr_t dest, const mpfr_t src)
  54. {
  55. mpfr_prec_t p_dest = mpfr_get_prec(dest);
  56. mpfr_prec_t p_src = mpfr_get_prec(src);
  57. if (p_dest != p_src)
  58. mpfr_set_prec(dest, p_src);
  59. }
  60. inline void mpfr_copy_precision(mpfr_t dest, const mpfr_t src1, const mpfr_t src2)
  61. {
  62. mpfr_prec_t p_dest = mpfr_get_prec(dest);
  63. mpfr_prec_t p_src1 = mpfr_get_prec(src1);
  64. mpfr_prec_t p_src2 = mpfr_get_prec(src2);
  65. if (p_src2 > p_src1)
  66. p_src1 = p_src2;
  67. if (p_dest != p_src1)
  68. mpfr_set_prec(dest, p_src1);
  69. }
  70. template <unsigned digits10, mpfr_allocation_type AllocationType>
  71. struct mpfr_float_imp;
  72. template <unsigned digits10>
  73. struct mpfr_float_imp<digits10, allocate_dynamic>
  74. {
  75. #ifdef BOOST_HAS_LONG_LONG
  76. typedef mpl::list<long, boost::long_long_type> signed_types;
  77. typedef mpl::list<unsigned long, boost::ulong_long_type> unsigned_types;
  78. #else
  79. typedef mpl::list<long> signed_types;
  80. typedef mpl::list<unsigned long> unsigned_types;
  81. #endif
  82. typedef mpl::list<double, long double> float_types;
  83. typedef long exponent_type;
  84. mpfr_float_imp()
  85. {
  86. mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  87. mpfr_set_ui(m_data, 0u, GMP_RNDN);
  88. }
  89. mpfr_float_imp(unsigned digits2)
  90. {
  91. mpfr_init2(m_data, digits2);
  92. mpfr_set_ui(m_data, 0u, GMP_RNDN);
  93. }
  94. mpfr_float_imp(const mpfr_float_imp& o)
  95. {
  96. mpfr_init2(m_data, mpfr_get_prec(o.m_data));
  97. if (o.m_data[0]._mpfr_d)
  98. mpfr_set(m_data, o.m_data, GMP_RNDN);
  99. }
  100. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  101. mpfr_float_imp(mpfr_float_imp&& o) BOOST_NOEXCEPT
  102. {
  103. m_data[0] = o.m_data[0];
  104. o.m_data[0]._mpfr_d = 0;
  105. }
  106. #endif
  107. mpfr_float_imp& operator=(const mpfr_float_imp& o)
  108. {
  109. if ((o.m_data[0]._mpfr_d) && (this != &o))
  110. {
  111. if (m_data[0]._mpfr_d == 0)
  112. mpfr_init2(m_data, mpfr_get_prec(o.m_data));
  113. mpfr_set(m_data, o.m_data, GMP_RNDN);
  114. }
  115. return *this;
  116. }
  117. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  118. mpfr_float_imp& operator=(mpfr_float_imp&& o) BOOST_NOEXCEPT
  119. {
  120. mpfr_swap(m_data, o.m_data);
  121. return *this;
  122. }
  123. #endif
  124. #ifdef BOOST_HAS_LONG_LONG
  125. #ifdef _MPFR_H_HAVE_INTMAX_T
  126. mpfr_float_imp& operator=(boost::ulong_long_type i)
  127. {
  128. if (m_data[0]._mpfr_d == 0)
  129. mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  130. mpfr_set_uj(m_data, i, GMP_RNDN);
  131. return *this;
  132. }
  133. mpfr_float_imp& operator=(boost::long_long_type i)
  134. {
  135. if (m_data[0]._mpfr_d == 0)
  136. mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  137. mpfr_set_sj(m_data, i, GMP_RNDN);
  138. return *this;
  139. }
  140. #else
  141. mpfr_float_imp& operator=(boost::ulong_long_type i)
  142. {
  143. if (m_data[0]._mpfr_d == 0)
  144. mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  145. boost::ulong_long_type mask = ((((1uLL << (std::numeric_limits<unsigned long>::digits - 1)) - 1) << 1) | 1uLL);
  146. unsigned shift = 0;
  147. mpfr_t t;
  148. mpfr_init2(t, (std::max)(static_cast<unsigned long>(std::numeric_limits<boost::ulong_long_type>::digits), mpfr_get_prec(m_data)));
  149. mpfr_set_ui(m_data, 0, GMP_RNDN);
  150. while (i)
  151. {
  152. mpfr_set_ui(t, static_cast<unsigned long>(i & mask), GMP_RNDN);
  153. if (shift)
  154. mpfr_mul_2exp(t, t, shift, GMP_RNDN);
  155. mpfr_add(m_data, m_data, t, GMP_RNDN);
  156. shift += std::numeric_limits<unsigned long>::digits;
  157. i >>= std::numeric_limits<unsigned long>::digits;
  158. }
  159. mpfr_clear(t);
  160. return *this;
  161. }
  162. mpfr_float_imp& operator=(boost::long_long_type i)
  163. {
  164. if (m_data[0]._mpfr_d == 0)
  165. mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  166. bool neg = i < 0;
  167. *this = boost::multiprecision::detail::unsigned_abs(i);
  168. if (neg)
  169. mpfr_neg(m_data, m_data, GMP_RNDN);
  170. return *this;
  171. }
  172. #endif
  173. #endif
  174. mpfr_float_imp& operator=(unsigned long i)
  175. {
  176. if (m_data[0]._mpfr_d == 0)
  177. mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  178. mpfr_set_ui(m_data, i, GMP_RNDN);
  179. return *this;
  180. }
  181. mpfr_float_imp& operator=(long i)
  182. {
  183. if (m_data[0]._mpfr_d == 0)
  184. mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  185. mpfr_set_si(m_data, i, GMP_RNDN);
  186. return *this;
  187. }
  188. mpfr_float_imp& operator=(double d)
  189. {
  190. if (m_data[0]._mpfr_d == 0)
  191. mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  192. mpfr_set_d(m_data, d, GMP_RNDN);
  193. return *this;
  194. }
  195. mpfr_float_imp& operator=(long double a)
  196. {
  197. if (m_data[0]._mpfr_d == 0)
  198. mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  199. mpfr_set_ld(m_data, a, GMP_RNDN);
  200. return *this;
  201. }
  202. mpfr_float_imp& operator=(const char* s)
  203. {
  204. if (m_data[0]._mpfr_d == 0)
  205. mpfr_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : (unsigned)get_default_precision()));
  206. if (mpfr_set_str(m_data, s, 10, GMP_RNDN) != 0)
  207. {
  208. BOOST_THROW_EXCEPTION(std::runtime_error(std::string("Unable to parse string \"") + s + std::string("\"as a valid floating point number.")));
  209. }
  210. return *this;
  211. }
  212. void swap(mpfr_float_imp& o) BOOST_NOEXCEPT
  213. {
  214. mpfr_swap(m_data, o.m_data);
  215. }
  216. std::string str(std::streamsize digits, std::ios_base::fmtflags f) const
  217. {
  218. BOOST_ASSERT(m_data[0]._mpfr_d);
  219. bool scientific = (f & std::ios_base::scientific) == std::ios_base::scientific;
  220. bool fixed = (f & std::ios_base::fixed) == std::ios_base::fixed;
  221. std::streamsize org_digits(digits);
  222. if (scientific && digits)
  223. ++digits;
  224. std::string result;
  225. mp_exp_t e;
  226. if (mpfr_inf_p(m_data))
  227. {
  228. if (mpfr_sgn(m_data) < 0)
  229. result = "-inf";
  230. else if (f & std::ios_base::showpos)
  231. result = "+inf";
  232. else
  233. result = "inf";
  234. return result;
  235. }
  236. if (mpfr_nan_p(m_data))
  237. {
  238. result = "nan";
  239. return result;
  240. }
  241. if (mpfr_zero_p(m_data))
  242. {
  243. e = 0;
  244. result = "0";
  245. }
  246. else
  247. {
  248. char* ps = mpfr_get_str(0, &e, 10, static_cast<std::size_t>(digits), m_data, GMP_RNDN);
  249. --e; // To match with what our formatter expects.
  250. if (fixed && e != -1)
  251. {
  252. // Oops we actually need a different number of digits to what we asked for:
  253. mpfr_free_str(ps);
  254. digits += e + 1;
  255. if (digits == 0)
  256. {
  257. // We need to get *all* the digits and then possibly round up,
  258. // we end up with either "0" or "1" as the result.
  259. ps = mpfr_get_str(0, &e, 10, 0, m_data, GMP_RNDN);
  260. --e;
  261. unsigned offset = *ps == '-' ? 1 : 0;
  262. if (ps[offset] > '5')
  263. {
  264. ++e;
  265. ps[offset] = '1';
  266. ps[offset + 1] = 0;
  267. }
  268. else if (ps[offset] == '5')
  269. {
  270. unsigned i = offset + 1;
  271. bool round_up = false;
  272. while (ps[i] != 0)
  273. {
  274. if (ps[i] != '0')
  275. {
  276. round_up = true;
  277. break;
  278. }
  279. ++i;
  280. }
  281. if (round_up)
  282. {
  283. ++e;
  284. ps[offset] = '1';
  285. ps[offset + 1] = 0;
  286. }
  287. else
  288. {
  289. ps[offset] = '0';
  290. ps[offset + 1] = 0;
  291. }
  292. }
  293. else
  294. {
  295. ps[offset] = '0';
  296. ps[offset + 1] = 0;
  297. }
  298. }
  299. else if (digits > 0)
  300. {
  301. mp_exp_t old_e = e;
  302. ps = mpfr_get_str(0, &e, 10, static_cast<std::size_t>(digits), m_data, GMP_RNDN);
  303. --e; // To match with what our formatter expects.
  304. if (old_e > e)
  305. {
  306. // in some cases, when we ask for more digits of precision, it will
  307. // change the number of digits to the left of the decimal, if that
  308. // happens, account for it here.
  309. // example: cout << fixed << setprecision(3) << mpf_float_50("99.9809")
  310. digits -= old_e - e;
  311. ps = mpfr_get_str(0, &e, 10, static_cast<std::size_t>(digits), m_data, GMP_RNDN);
  312. --e; // To match with what our formatter expects.
  313. }
  314. }
  315. else
  316. {
  317. ps = mpfr_get_str(0, &e, 10, 1, m_data, GMP_RNDN);
  318. --e;
  319. unsigned offset = *ps == '-' ? 1 : 0;
  320. ps[offset] = '0';
  321. ps[offset + 1] = 0;
  322. }
  323. }
  324. result = ps ? ps : "0";
  325. if (ps)
  326. mpfr_free_str(ps);
  327. }
  328. boost::multiprecision::detail::format_float_string(result, e, org_digits, f, 0 != mpfr_zero_p(m_data));
  329. return result;
  330. }
  331. ~mpfr_float_imp() BOOST_NOEXCEPT
  332. {
  333. if (m_data[0]._mpfr_d)
  334. mpfr_clear(m_data);
  335. detail::mpfr_cleanup<true>::force_instantiate();
  336. }
  337. void negate() BOOST_NOEXCEPT
  338. {
  339. BOOST_ASSERT(m_data[0]._mpfr_d);
  340. mpfr_neg(m_data, m_data, GMP_RNDN);
  341. }
  342. template <mpfr_allocation_type AllocationType>
  343. int compare(const mpfr_float_backend<digits10, AllocationType>& o) const BOOST_NOEXCEPT
  344. {
  345. BOOST_ASSERT(m_data[0]._mpfr_d && o.m_data[0]._mpfr_d);
  346. return mpfr_cmp(m_data, o.m_data);
  347. }
  348. int compare(long i) const BOOST_NOEXCEPT
  349. {
  350. BOOST_ASSERT(m_data[0]._mpfr_d);
  351. return mpfr_cmp_si(m_data, i);
  352. }
  353. int compare(unsigned long i) const BOOST_NOEXCEPT
  354. {
  355. BOOST_ASSERT(m_data[0]._mpfr_d);
  356. return mpfr_cmp_ui(m_data, i);
  357. }
  358. template <class V>
  359. int compare(V v) const BOOST_NOEXCEPT
  360. {
  361. mpfr_float_backend<digits10, allocate_dynamic> d(0uL, mpfr_get_prec(m_data));
  362. d = v;
  363. return compare(d);
  364. }
  365. mpfr_t& data() BOOST_NOEXCEPT
  366. {
  367. BOOST_ASSERT(m_data[0]._mpfr_d);
  368. return m_data;
  369. }
  370. const mpfr_t& data() const BOOST_NOEXCEPT
  371. {
  372. BOOST_ASSERT(m_data[0]._mpfr_d);
  373. return m_data;
  374. }
  375. protected:
  376. mpfr_t m_data;
  377. static boost::multiprecision::detail::precision_type& get_default_precision() BOOST_NOEXCEPT
  378. {
  379. static boost::multiprecision::detail::precision_type val(BOOST_MULTIPRECISION_MPFR_DEFAULT_PRECISION);
  380. return val;
  381. }
  382. };
  383. #ifdef BOOST_MSVC
  384. #pragma warning(push)
  385. #pragma warning(disable : 4127) // Conditional expression is constant
  386. #endif
  387. template <unsigned digits10>
  388. struct mpfr_float_imp<digits10, allocate_stack>
  389. {
  390. #ifdef BOOST_HAS_LONG_LONG
  391. typedef mpl::list<long, boost::long_long_type> signed_types;
  392. typedef mpl::list<unsigned long, boost::ulong_long_type> unsigned_types;
  393. #else
  394. typedef mpl::list<long> signed_types;
  395. typedef mpl::list<unsigned long> unsigned_types;
  396. #endif
  397. typedef mpl::list<double, long double> float_types;
  398. typedef long exponent_type;
  399. static const unsigned digits2 = (digits10 * 1000uL) / 301uL + ((digits10 * 1000uL) % 301 ? 2u : 1u);
  400. static const unsigned limb_count = mpfr_custom_get_size(digits2) / sizeof(mp_limb_t);
  401. ~mpfr_float_imp() BOOST_NOEXCEPT
  402. {
  403. detail::mpfr_cleanup<true>::force_instantiate();
  404. }
  405. mpfr_float_imp()
  406. {
  407. mpfr_custom_init(m_buffer, digits2);
  408. mpfr_custom_init_set(m_data, MPFR_NAN_KIND, 0, digits2, m_buffer);
  409. mpfr_set_ui(m_data, 0u, GMP_RNDN);
  410. }
  411. mpfr_float_imp(const mpfr_float_imp& o)
  412. {
  413. mpfr_custom_init(m_buffer, digits2);
  414. mpfr_custom_init_set(m_data, MPFR_NAN_KIND, 0, digits2, m_buffer);
  415. mpfr_set(m_data, o.m_data, GMP_RNDN);
  416. }
  417. mpfr_float_imp& operator=(const mpfr_float_imp& o)
  418. {
  419. mpfr_set(m_data, o.m_data, GMP_RNDN);
  420. return *this;
  421. }
  422. #ifdef BOOST_HAS_LONG_LONG
  423. #ifdef _MPFR_H_HAVE_INTMAX_T
  424. mpfr_float_imp& operator=(boost::ulong_long_type i)
  425. {
  426. mpfr_set_uj(m_data, i, GMP_RNDN);
  427. return *this;
  428. }
  429. mpfr_float_imp& operator=(boost::long_long_type i)
  430. {
  431. mpfr_set_sj(m_data, i, GMP_RNDN);
  432. return *this;
  433. }
  434. #else
  435. mpfr_float_imp& operator=(boost::ulong_long_type i)
  436. {
  437. boost::ulong_long_type mask = ((((1uLL << (std::numeric_limits<unsigned long>::digits - 1)) - 1) << 1) | 1uL);
  438. unsigned shift = 0;
  439. mpfr_t t;
  440. mp_limb_t t_limbs[limb_count];
  441. mpfr_custom_init(t_limbs, digits2);
  442. mpfr_custom_init_set(t, MPFR_NAN_KIND, 0, digits2, t_limbs);
  443. mpfr_set_ui(m_data, 0, GMP_RNDN);
  444. while (i)
  445. {
  446. mpfr_set_ui(t, static_cast<unsigned long>(i & mask), GMP_RNDN);
  447. if (shift)
  448. mpfr_mul_2exp(t, t, shift, GMP_RNDN);
  449. mpfr_add(m_data, m_data, t, GMP_RNDN);
  450. shift += std::numeric_limits<unsigned long>::digits;
  451. i >>= std::numeric_limits<unsigned long>::digits;
  452. }
  453. return *this;
  454. }
  455. mpfr_float_imp& operator=(boost::long_long_type i)
  456. {
  457. bool neg = i < 0;
  458. *this = boost::multiprecision::detail::unsigned_abs(i);
  459. if (neg)
  460. mpfr_neg(m_data, m_data, GMP_RNDN);
  461. return *this;
  462. }
  463. #endif
  464. #endif
  465. mpfr_float_imp& operator=(unsigned long i)
  466. {
  467. mpfr_set_ui(m_data, i, GMP_RNDN);
  468. return *this;
  469. }
  470. mpfr_float_imp& operator=(long i)
  471. {
  472. mpfr_set_si(m_data, i, GMP_RNDN);
  473. return *this;
  474. }
  475. mpfr_float_imp& operator=(double d)
  476. {
  477. mpfr_set_d(m_data, d, GMP_RNDN);
  478. return *this;
  479. }
  480. mpfr_float_imp& operator=(long double a)
  481. {
  482. mpfr_set_ld(m_data, a, GMP_RNDN);
  483. return *this;
  484. }
  485. mpfr_float_imp& operator=(const char* s)
  486. {
  487. if (mpfr_set_str(m_data, s, 10, GMP_RNDN) != 0)
  488. {
  489. BOOST_THROW_EXCEPTION(std::runtime_error(std::string("Unable to parse string \"") + s + std::string("\"as a valid floating point number.")));
  490. }
  491. return *this;
  492. }
  493. void swap(mpfr_float_imp& o) BOOST_NOEXCEPT
  494. {
  495. // We have to swap by copying:
  496. mpfr_float_imp t(*this);
  497. *this = o;
  498. o = t;
  499. }
  500. std::string str(std::streamsize digits, std::ios_base::fmtflags f) const
  501. {
  502. BOOST_ASSERT(m_data[0]._mpfr_d);
  503. bool scientific = (f & std::ios_base::scientific) == std::ios_base::scientific;
  504. bool fixed = (f & std::ios_base::fixed) == std::ios_base::fixed;
  505. std::streamsize org_digits(digits);
  506. if (scientific && digits)
  507. ++digits;
  508. std::string result;
  509. mp_exp_t e;
  510. if (mpfr_inf_p(m_data))
  511. {
  512. if (mpfr_sgn(m_data) < 0)
  513. result = "-inf";
  514. else if (f & std::ios_base::showpos)
  515. result = "+inf";
  516. else
  517. result = "inf";
  518. return result;
  519. }
  520. if (mpfr_nan_p(m_data))
  521. {
  522. result = "nan";
  523. return result;
  524. }
  525. if (mpfr_zero_p(m_data))
  526. {
  527. e = 0;
  528. result = "0";
  529. }
  530. else
  531. {
  532. char* ps = mpfr_get_str(0, &e, 10, static_cast<std::size_t>(digits), m_data, GMP_RNDN);
  533. --e; // To match with what our formatter expects.
  534. if (fixed && e != -1)
  535. {
  536. // Oops we actually need a different number of digits to what we asked for:
  537. mpfr_free_str(ps);
  538. digits += e + 1;
  539. if (digits == 0)
  540. {
  541. // We need to get *all* the digits and then possibly round up,
  542. // we end up with either "0" or "1" as the result.
  543. ps = mpfr_get_str(0, &e, 10, 0, m_data, GMP_RNDN);
  544. --e;
  545. unsigned offset = *ps == '-' ? 1 : 0;
  546. if (ps[offset] > '5')
  547. {
  548. ++e;
  549. ps[offset] = '1';
  550. ps[offset + 1] = 0;
  551. }
  552. else if (ps[offset] == '5')
  553. {
  554. unsigned i = offset + 1;
  555. bool round_up = false;
  556. while (ps[i] != 0)
  557. {
  558. if (ps[i] != '0')
  559. {
  560. round_up = true;
  561. break;
  562. }
  563. }
  564. if (round_up)
  565. {
  566. ++e;
  567. ps[offset] = '1';
  568. ps[offset + 1] = 0;
  569. }
  570. else
  571. {
  572. ps[offset] = '0';
  573. ps[offset + 1] = 0;
  574. }
  575. }
  576. else
  577. {
  578. ps[offset] = '0';
  579. ps[offset + 1] = 0;
  580. }
  581. }
  582. else if (digits > 0)
  583. {
  584. ps = mpfr_get_str(0, &e, 10, static_cast<std::size_t>(digits), m_data, GMP_RNDN);
  585. --e; // To match with what our formatter expects.
  586. }
  587. else
  588. {
  589. ps = mpfr_get_str(0, &e, 10, 1, m_data, GMP_RNDN);
  590. --e;
  591. unsigned offset = *ps == '-' ? 1 : 0;
  592. ps[offset] = '0';
  593. ps[offset + 1] = 0;
  594. }
  595. }
  596. result = ps ? ps : "0";
  597. if (ps)
  598. mpfr_free_str(ps);
  599. }
  600. boost::multiprecision::detail::format_float_string(result, e, org_digits, f, 0 != mpfr_zero_p(m_data));
  601. return result;
  602. }
  603. void negate() BOOST_NOEXCEPT
  604. {
  605. mpfr_neg(m_data, m_data, GMP_RNDN);
  606. }
  607. template <mpfr_allocation_type AllocationType>
  608. int compare(const mpfr_float_backend<digits10, AllocationType>& o) const BOOST_NOEXCEPT
  609. {
  610. return mpfr_cmp(m_data, o.m_data);
  611. }
  612. int compare(long i) const BOOST_NOEXCEPT
  613. {
  614. return mpfr_cmp_si(m_data, i);
  615. }
  616. int compare(unsigned long i) const BOOST_NOEXCEPT
  617. {
  618. return mpfr_cmp_ui(m_data, i);
  619. }
  620. template <class V>
  621. int compare(V v) const BOOST_NOEXCEPT
  622. {
  623. mpfr_float_backend<digits10, allocate_stack> d;
  624. d = v;
  625. return compare(d);
  626. }
  627. mpfr_t& data() BOOST_NOEXCEPT
  628. {
  629. return m_data;
  630. }
  631. const mpfr_t& data() const BOOST_NOEXCEPT
  632. {
  633. return m_data;
  634. }
  635. protected:
  636. mpfr_t m_data;
  637. mp_limb_t m_buffer[limb_count];
  638. };
  639. #ifdef BOOST_MSVC
  640. #pragma warning(pop)
  641. #endif
  642. } // namespace detail
  643. template <unsigned digits10, mpfr_allocation_type AllocationType>
  644. struct mpfr_float_backend : public detail::mpfr_float_imp<digits10, AllocationType>
  645. {
  646. mpfr_float_backend() : detail::mpfr_float_imp<digits10, AllocationType>() {}
  647. mpfr_float_backend(const mpfr_float_backend& o) : detail::mpfr_float_imp<digits10, AllocationType>(o) {}
  648. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  649. mpfr_float_backend(mpfr_float_backend&& o) BOOST_NOEXCEPT : detail::mpfr_float_imp<digits10, AllocationType>(static_cast<detail::mpfr_float_imp<digits10, AllocationType>&&>(o))
  650. {}
  651. #endif
  652. template <unsigned D, mpfr_allocation_type AT>
  653. mpfr_float_backend(const mpfr_float_backend<D, AT>& val, typename enable_if_c<D <= digits10>::type* = 0)
  654. : detail::mpfr_float_imp<digits10, AllocationType>()
  655. {
  656. mpfr_set(this->m_data, val.data(), GMP_RNDN);
  657. }
  658. template <unsigned D, mpfr_allocation_type AT>
  659. explicit mpfr_float_backend(const mpfr_float_backend<D, AT>& val, typename disable_if_c<D <= digits10>::type* = 0)
  660. : detail::mpfr_float_imp<digits10, AllocationType>()
  661. {
  662. mpfr_set(this->m_data, val.data(), GMP_RNDN);
  663. }
  664. template <unsigned D>
  665. mpfr_float_backend(const gmp_float<D>& val, typename enable_if_c<D <= digits10>::type* = 0)
  666. : detail::mpfr_float_imp<digits10, AllocationType>()
  667. {
  668. mpfr_set_f(this->m_data, val.data(), GMP_RNDN);
  669. }
  670. template <unsigned D>
  671. mpfr_float_backend(const gmp_float<D>& val, typename disable_if_c<D <= digits10>::type* = 0)
  672. : detail::mpfr_float_imp<digits10, AllocationType>()
  673. {
  674. mpfr_set_f(this->m_data, val.data(), GMP_RNDN);
  675. }
  676. mpfr_float_backend(const gmp_int& val)
  677. : detail::mpfr_float_imp<digits10, AllocationType>()
  678. {
  679. mpfr_set_z(this->m_data, val.data(), GMP_RNDN);
  680. }
  681. mpfr_float_backend(const gmp_rational& val)
  682. : detail::mpfr_float_imp<digits10, AllocationType>()
  683. {
  684. mpfr_set_q(this->m_data, val.data(), GMP_RNDN);
  685. }
  686. mpfr_float_backend(const mpfr_t val)
  687. : detail::mpfr_float_imp<digits10, AllocationType>()
  688. {
  689. mpfr_set(this->m_data, val, GMP_RNDN);
  690. }
  691. mpfr_float_backend(const mpf_t val)
  692. : detail::mpfr_float_imp<digits10, AllocationType>()
  693. {
  694. mpfr_set_f(this->m_data, val, GMP_RNDN);
  695. }
  696. mpfr_float_backend(const mpz_t val)
  697. : detail::mpfr_float_imp<digits10, AllocationType>()
  698. {
  699. mpfr_set_z(this->m_data, val, GMP_RNDN);
  700. }
  701. mpfr_float_backend(const mpq_t val)
  702. : detail::mpfr_float_imp<digits10, AllocationType>()
  703. {
  704. mpfr_set_q(this->m_data, val, GMP_RNDN);
  705. }
  706. // Construction with precision: we ignore the precision here.
  707. template <class V>
  708. mpfr_float_backend(const V& o, unsigned)
  709. {
  710. *this = o;
  711. }
  712. mpfr_float_backend& operator=(const mpfr_float_backend& o)
  713. {
  714. *static_cast<detail::mpfr_float_imp<digits10, AllocationType>*>(this) = static_cast<detail::mpfr_float_imp<digits10, AllocationType> const&>(o);
  715. return *this;
  716. }
  717. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  718. mpfr_float_backend& operator=(mpfr_float_backend&& o) BOOST_NOEXCEPT
  719. {
  720. *static_cast<detail::mpfr_float_imp<digits10, AllocationType>*>(this) = static_cast<detail::mpfr_float_imp<digits10, AllocationType>&&>(o);
  721. return *this;
  722. }
  723. #endif
  724. template <class V>
  725. mpfr_float_backend& operator=(const V& v)
  726. {
  727. *static_cast<detail::mpfr_float_imp<digits10, AllocationType>*>(this) = v;
  728. return *this;
  729. }
  730. mpfr_float_backend& operator=(const mpfr_t val)
  731. {
  732. if (this->m_data[0]._mpfr_d == 0)
  733. mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
  734. mpfr_set(this->m_data, val, GMP_RNDN);
  735. return *this;
  736. }
  737. mpfr_float_backend& operator=(const mpf_t val)
  738. {
  739. if (this->m_data[0]._mpfr_d == 0)
  740. mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
  741. mpfr_set_f(this->m_data, val, GMP_RNDN);
  742. return *this;
  743. }
  744. mpfr_float_backend& operator=(const mpz_t val)
  745. {
  746. if (this->m_data[0]._mpfr_d == 0)
  747. mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
  748. mpfr_set_z(this->m_data, val, GMP_RNDN);
  749. return *this;
  750. }
  751. mpfr_float_backend& operator=(const mpq_t val)
  752. {
  753. if (this->m_data[0]._mpfr_d == 0)
  754. mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
  755. mpfr_set_q(this->m_data, val, GMP_RNDN);
  756. return *this;
  757. }
  758. // We don't change our precision here, this is a fixed precision type:
  759. template <unsigned D, mpfr_allocation_type AT>
  760. mpfr_float_backend& operator=(const mpfr_float_backend<D, AT>& val)
  761. {
  762. if (this->m_data[0]._mpfr_d == 0)
  763. mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
  764. mpfr_set(this->m_data, val.data(), GMP_RNDN);
  765. return *this;
  766. }
  767. template <unsigned D>
  768. mpfr_float_backend& operator=(const gmp_float<D>& val)
  769. {
  770. if (this->m_data[0]._mpfr_d == 0)
  771. mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
  772. mpfr_set_f(this->m_data, val.data(), GMP_RNDN);
  773. return *this;
  774. }
  775. mpfr_float_backend& operator=(const gmp_int& val)
  776. {
  777. if (this->m_data[0]._mpfr_d == 0)
  778. mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
  779. mpfr_set_z(this->m_data, val.data(), GMP_RNDN);
  780. return *this;
  781. }
  782. mpfr_float_backend& operator=(const gmp_rational& val)
  783. {
  784. if (this->m_data[0]._mpfr_d == 0)
  785. mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(digits10));
  786. mpfr_set_q(this->m_data, val.data(), GMP_RNDN);
  787. return *this;
  788. }
  789. };
  790. template <>
  791. struct mpfr_float_backend<0, allocate_dynamic> : public detail::mpfr_float_imp<0, allocate_dynamic>
  792. {
  793. mpfr_float_backend() : detail::mpfr_float_imp<0, allocate_dynamic>() {}
  794. mpfr_float_backend(const mpfr_t val)
  795. : detail::mpfr_float_imp<0, allocate_dynamic>((unsigned)mpfr_get_prec(val))
  796. {
  797. mpfr_set(this->m_data, val, GMP_RNDN);
  798. }
  799. mpfr_float_backend(const mpf_t val)
  800. : detail::mpfr_float_imp<0, allocate_dynamic>((unsigned)mpf_get_prec(val))
  801. {
  802. mpfr_set_f(this->m_data, val, GMP_RNDN);
  803. }
  804. mpfr_float_backend(const mpz_t val)
  805. : detail::mpfr_float_imp<0, allocate_dynamic>()
  806. {
  807. mpfr_set_z(this->m_data, val, GMP_RNDN);
  808. }
  809. mpfr_float_backend(const mpq_t val)
  810. : detail::mpfr_float_imp<0, allocate_dynamic>()
  811. {
  812. mpfr_set_q(this->m_data, val, GMP_RNDN);
  813. }
  814. mpfr_float_backend(const mpfr_float_backend& o) : detail::mpfr_float_imp<0, allocate_dynamic>(o) {}
  815. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  816. mpfr_float_backend(mpfr_float_backend&& o) BOOST_NOEXCEPT : detail::mpfr_float_imp<0, allocate_dynamic>(static_cast<detail::mpfr_float_imp<0, allocate_dynamic>&&>(o))
  817. {}
  818. #endif
  819. template <class V>
  820. mpfr_float_backend(const V& o, unsigned digits10)
  821. : detail::mpfr_float_imp<0, allocate_dynamic>(multiprecision::detail::digits10_2_2(digits10))
  822. {
  823. *this = o;
  824. }
  825. #ifndef BOOST_NO_CXX17_HDR_STRING_VIEW
  826. mpfr_float_backend(const std::string_view& o, unsigned digits10)
  827. : detail::mpfr_float_imp<0, allocate_dynamic>(multiprecision::detail::digits10_2_2(digits10))
  828. {
  829. std::string s(o);
  830. *this = s.c_str();
  831. }
  832. #endif
  833. template <unsigned D>
  834. mpfr_float_backend(const gmp_float<D>& val, unsigned digits10)
  835. : detail::mpfr_float_imp<0, allocate_dynamic>(multiprecision::detail::digits10_2_2(digits10))
  836. {
  837. mpfr_set_f(this->m_data, val.data(), GMP_RNDN);
  838. }
  839. template <unsigned D>
  840. mpfr_float_backend(const mpfr_float_backend<D>& val, unsigned digits10)
  841. : detail::mpfr_float_imp<0, allocate_dynamic>(multiprecision::detail::digits10_2_2(digits10))
  842. {
  843. mpfr_set(this->m_data, val.data(), GMP_RNDN);
  844. }
  845. template <unsigned D>
  846. mpfr_float_backend(const mpfr_float_backend<D>& val)
  847. : detail::mpfr_float_imp<0, allocate_dynamic>(mpfr_get_prec(val.data()))
  848. {
  849. mpfr_set(this->m_data, val.data(), GMP_RNDN);
  850. }
  851. template <unsigned D>
  852. mpfr_float_backend(const gmp_float<D>& val)
  853. : detail::mpfr_float_imp<0, allocate_dynamic>(mpf_get_prec(val.data()))
  854. {
  855. mpfr_set_f(this->m_data, val.data(), GMP_RNDN);
  856. }
  857. mpfr_float_backend(const gmp_int& val)
  858. : detail::mpfr_float_imp<0, allocate_dynamic>()
  859. {
  860. mpfr_set_z(this->m_data, val.data(), GMP_RNDN);
  861. }
  862. mpfr_float_backend(const gmp_rational& val)
  863. : detail::mpfr_float_imp<0, allocate_dynamic>()
  864. {
  865. mpfr_set_q(this->m_data, val.data(), GMP_RNDN);
  866. }
  867. mpfr_float_backend& operator=(const mpfr_float_backend& o)
  868. {
  869. if (this != &o)
  870. {
  871. if (this->m_data[0]._mpfr_d == 0)
  872. mpfr_init2(this->m_data, mpfr_get_prec(o.data()));
  873. else
  874. detail::mpfr_copy_precision(this->m_data, o.data());
  875. mpfr_set(this->m_data, o.data(), GMP_RNDN);
  876. }
  877. return *this;
  878. }
  879. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  880. mpfr_float_backend& operator=(mpfr_float_backend&& o) BOOST_NOEXCEPT
  881. {
  882. *static_cast<detail::mpfr_float_imp<0, allocate_dynamic>*>(this) = static_cast<detail::mpfr_float_imp<0, allocate_dynamic>&&>(o);
  883. return *this;
  884. }
  885. #endif
  886. template <class V>
  887. mpfr_float_backend& operator=(const V& v)
  888. {
  889. *static_cast<detail::mpfr_float_imp<0, allocate_dynamic>*>(this) = v;
  890. return *this;
  891. }
  892. mpfr_float_backend& operator=(const mpfr_t val)
  893. {
  894. if (this->m_data[0]._mpfr_d == 0)
  895. mpfr_init2(this->m_data, mpfr_get_prec(val));
  896. else
  897. mpfr_set_prec(this->m_data, mpfr_get_prec(val));
  898. mpfr_set(this->m_data, val, GMP_RNDN);
  899. return *this;
  900. }
  901. mpfr_float_backend& operator=(const mpf_t val)
  902. {
  903. if (this->m_data[0]._mpfr_d == 0)
  904. mpfr_init2(this->m_data, (mpfr_prec_t)mpf_get_prec(val));
  905. else
  906. mpfr_set_prec(this->m_data, (unsigned)mpf_get_prec(val));
  907. mpfr_set_f(this->m_data, val, GMP_RNDN);
  908. return *this;
  909. }
  910. mpfr_float_backend& operator=(const mpz_t val)
  911. {
  912. if (this->m_data[0]._mpfr_d == 0)
  913. mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(get_default_precision()));
  914. mpfr_set_z(this->m_data, val, GMP_RNDN);
  915. return *this;
  916. }
  917. mpfr_float_backend& operator=(const mpq_t val)
  918. {
  919. if (this->m_data[0]._mpfr_d == 0)
  920. mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(get_default_precision()));
  921. mpfr_set_q(this->m_data, val, GMP_RNDN);
  922. return *this;
  923. }
  924. template <unsigned D>
  925. mpfr_float_backend& operator=(const mpfr_float_backend<D>& val)
  926. {
  927. if (this->m_data[0]._mpfr_d == 0)
  928. mpfr_init2(this->m_data, mpfr_get_prec(val.data()));
  929. else
  930. mpfr_set_prec(this->m_data, mpfr_get_prec(val.data()));
  931. mpfr_set(this->m_data, val.data(), GMP_RNDN);
  932. return *this;
  933. }
  934. template <unsigned D>
  935. mpfr_float_backend& operator=(const gmp_float<D>& val)
  936. {
  937. if (this->m_data[0]._mpfr_d == 0)
  938. mpfr_init2(this->m_data, mpf_get_prec(val.data()));
  939. else
  940. mpfr_set_prec(this->m_data, mpf_get_prec(val.data()));
  941. mpfr_set_f(this->m_data, val.data(), GMP_RNDN);
  942. return *this;
  943. }
  944. mpfr_float_backend& operator=(const gmp_int& val)
  945. {
  946. if (this->m_data[0]._mpfr_d == 0)
  947. mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(get_default_precision()));
  948. mpfr_set_z(this->m_data, val.data(), GMP_RNDN);
  949. return *this;
  950. }
  951. mpfr_float_backend& operator=(const gmp_rational& val)
  952. {
  953. if (this->m_data[0]._mpfr_d == 0)
  954. mpfr_init2(this->m_data, multiprecision::detail::digits10_2_2(get_default_precision()));
  955. mpfr_set_q(this->m_data, val.data(), GMP_RNDN);
  956. return *this;
  957. }
  958. static unsigned default_precision() BOOST_NOEXCEPT
  959. {
  960. return get_default_precision();
  961. }
  962. static void default_precision(unsigned v) BOOST_NOEXCEPT
  963. {
  964. get_default_precision() = v;
  965. }
  966. unsigned precision() const BOOST_NOEXCEPT
  967. {
  968. return multiprecision::detail::digits2_2_10(mpfr_get_prec(this->m_data));
  969. }
  970. void precision(unsigned digits10) BOOST_NOEXCEPT
  971. {
  972. mpfr_prec_round(this->m_data, multiprecision::detail::digits10_2_2((digits10)), GMP_RNDN);
  973. }
  974. };
  975. template <unsigned digits10, mpfr_allocation_type AllocationType, class T>
  976. inline typename enable_if<is_arithmetic<T>, bool>::type eval_eq(const mpfr_float_backend<digits10, AllocationType>& a, const T& b) BOOST_NOEXCEPT
  977. {
  978. return a.compare(b) == 0;
  979. }
  980. template <unsigned digits10, mpfr_allocation_type AllocationType, class T>
  981. inline typename enable_if<is_arithmetic<T>, bool>::type eval_lt(const mpfr_float_backend<digits10, AllocationType>& a, const T& b) BOOST_NOEXCEPT
  982. {
  983. return a.compare(b) < 0;
  984. }
  985. template <unsigned digits10, mpfr_allocation_type AllocationType, class T>
  986. inline typename enable_if<is_arithmetic<T>, bool>::type eval_gt(const mpfr_float_backend<digits10, AllocationType>& a, const T& b) BOOST_NOEXCEPT
  987. {
  988. return a.compare(b) > 0;
  989. }
  990. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  991. inline void eval_add(mpfr_float_backend<D1, A1>& result, const mpfr_float_backend<D2, A2>& o)
  992. {
  993. mpfr_add(result.data(), result.data(), o.data(), GMP_RNDN);
  994. }
  995. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  996. inline void eval_subtract(mpfr_float_backend<D1, A1>& result, const mpfr_float_backend<D2, A2>& o)
  997. {
  998. mpfr_sub(result.data(), result.data(), o.data(), GMP_RNDN);
  999. }
  1000. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1001. inline void eval_multiply(mpfr_float_backend<D1, A1>& result, const mpfr_float_backend<D2, A2>& o)
  1002. {
  1003. if ((void*)&o == (void*)&result)
  1004. mpfr_sqr(result.data(), o.data(), GMP_RNDN);
  1005. else
  1006. mpfr_mul(result.data(), result.data(), o.data(), GMP_RNDN);
  1007. }
  1008. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1009. inline void eval_divide(mpfr_float_backend<D1, A1>& result, const mpfr_float_backend<D2, A2>& o)
  1010. {
  1011. mpfr_div(result.data(), result.data(), o.data(), GMP_RNDN);
  1012. }
  1013. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1014. inline void eval_add(mpfr_float_backend<digits10, AllocationType>& result, unsigned long i)
  1015. {
  1016. mpfr_add_ui(result.data(), result.data(), i, GMP_RNDN);
  1017. }
  1018. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1019. inline void eval_subtract(mpfr_float_backend<digits10, AllocationType>& result, unsigned long i)
  1020. {
  1021. mpfr_sub_ui(result.data(), result.data(), i, GMP_RNDN);
  1022. }
  1023. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1024. inline void eval_multiply(mpfr_float_backend<digits10, AllocationType>& result, unsigned long i)
  1025. {
  1026. mpfr_mul_ui(result.data(), result.data(), i, GMP_RNDN);
  1027. }
  1028. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1029. inline void eval_divide(mpfr_float_backend<digits10, AllocationType>& result, unsigned long i)
  1030. {
  1031. mpfr_div_ui(result.data(), result.data(), i, GMP_RNDN);
  1032. }
  1033. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1034. inline void eval_add(mpfr_float_backend<digits10, AllocationType>& result, long i)
  1035. {
  1036. if (i > 0)
  1037. mpfr_add_ui(result.data(), result.data(), i, GMP_RNDN);
  1038. else
  1039. mpfr_sub_ui(result.data(), result.data(), boost::multiprecision::detail::unsigned_abs(i), GMP_RNDN);
  1040. }
  1041. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1042. inline void eval_subtract(mpfr_float_backend<digits10, AllocationType>& result, long i)
  1043. {
  1044. if (i > 0)
  1045. mpfr_sub_ui(result.data(), result.data(), i, GMP_RNDN);
  1046. else
  1047. mpfr_add_ui(result.data(), result.data(), boost::multiprecision::detail::unsigned_abs(i), GMP_RNDN);
  1048. }
  1049. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1050. inline void eval_multiply(mpfr_float_backend<digits10, AllocationType>& result, long i)
  1051. {
  1052. mpfr_mul_ui(result.data(), result.data(), boost::multiprecision::detail::unsigned_abs(i), GMP_RNDN);
  1053. if (i < 0)
  1054. mpfr_neg(result.data(), result.data(), GMP_RNDN);
  1055. }
  1056. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1057. inline void eval_divide(mpfr_float_backend<digits10, AllocationType>& result, long i)
  1058. {
  1059. mpfr_div_ui(result.data(), result.data(), boost::multiprecision::detail::unsigned_abs(i), GMP_RNDN);
  1060. if (i < 0)
  1061. mpfr_neg(result.data(), result.data(), GMP_RNDN);
  1062. }
  1063. //
  1064. // Specialised 3 arg versions of the basic operators:
  1065. //
  1066. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2, unsigned D3>
  1067. inline void eval_add(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, const mpfr_float_backend<D3>& y)
  1068. {
  1069. mpfr_add(a.data(), x.data(), y.data(), GMP_RNDN);
  1070. }
  1071. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1072. inline void eval_add(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, unsigned long y)
  1073. {
  1074. mpfr_add_ui(a.data(), x.data(), y, GMP_RNDN);
  1075. }
  1076. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1077. inline void eval_add(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, long y)
  1078. {
  1079. if (y < 0)
  1080. mpfr_sub_ui(a.data(), x.data(), boost::multiprecision::detail::unsigned_abs(y), GMP_RNDN);
  1081. else
  1082. mpfr_add_ui(a.data(), x.data(), y, GMP_RNDN);
  1083. }
  1084. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1085. inline void eval_add(mpfr_float_backend<D1, A1>& a, unsigned long x, const mpfr_float_backend<D2, A2>& y)
  1086. {
  1087. mpfr_add_ui(a.data(), y.data(), x, GMP_RNDN);
  1088. }
  1089. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1090. inline void eval_add(mpfr_float_backend<D1, A1>& a, long x, const mpfr_float_backend<D2, A2>& y)
  1091. {
  1092. if (x < 0)
  1093. {
  1094. mpfr_ui_sub(a.data(), boost::multiprecision::detail::unsigned_abs(x), y.data(), GMP_RNDN);
  1095. mpfr_neg(a.data(), a.data(), GMP_RNDN);
  1096. }
  1097. else
  1098. mpfr_add_ui(a.data(), y.data(), x, GMP_RNDN);
  1099. }
  1100. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2, unsigned D3>
  1101. inline void eval_subtract(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, const mpfr_float_backend<D3>& y)
  1102. {
  1103. mpfr_sub(a.data(), x.data(), y.data(), GMP_RNDN);
  1104. }
  1105. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1106. inline void eval_subtract(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, unsigned long y)
  1107. {
  1108. mpfr_sub_ui(a.data(), x.data(), y, GMP_RNDN);
  1109. }
  1110. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1111. inline void eval_subtract(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, long y)
  1112. {
  1113. if (y < 0)
  1114. mpfr_add_ui(a.data(), x.data(), boost::multiprecision::detail::unsigned_abs(y), GMP_RNDN);
  1115. else
  1116. mpfr_sub_ui(a.data(), x.data(), y, GMP_RNDN);
  1117. }
  1118. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1119. inline void eval_subtract(mpfr_float_backend<D1, A1>& a, unsigned long x, const mpfr_float_backend<D2, A2>& y)
  1120. {
  1121. mpfr_ui_sub(a.data(), x, y.data(), GMP_RNDN);
  1122. }
  1123. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1124. inline void eval_subtract(mpfr_float_backend<D1, A1>& a, long x, const mpfr_float_backend<D2, A2>& y)
  1125. {
  1126. if (x < 0)
  1127. {
  1128. mpfr_add_ui(a.data(), y.data(), boost::multiprecision::detail::unsigned_abs(x), GMP_RNDN);
  1129. mpfr_neg(a.data(), a.data(), GMP_RNDN);
  1130. }
  1131. else
  1132. mpfr_ui_sub(a.data(), x, y.data(), GMP_RNDN);
  1133. }
  1134. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2, unsigned D3>
  1135. inline void eval_multiply(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, const mpfr_float_backend<D3>& y)
  1136. {
  1137. if ((void*)&x == (void*)&y)
  1138. mpfr_sqr(a.data(), x.data(), GMP_RNDN);
  1139. else
  1140. mpfr_mul(a.data(), x.data(), y.data(), GMP_RNDN);
  1141. }
  1142. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1143. inline void eval_multiply(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, unsigned long y)
  1144. {
  1145. mpfr_mul_ui(a.data(), x.data(), y, GMP_RNDN);
  1146. }
  1147. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1148. inline void eval_multiply(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, long y)
  1149. {
  1150. if (y < 0)
  1151. {
  1152. mpfr_mul_ui(a.data(), x.data(), boost::multiprecision::detail::unsigned_abs(y), GMP_RNDN);
  1153. a.negate();
  1154. }
  1155. else
  1156. mpfr_mul_ui(a.data(), x.data(), y, GMP_RNDN);
  1157. }
  1158. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1159. inline void eval_multiply(mpfr_float_backend<D1, A1>& a, unsigned long x, const mpfr_float_backend<D2, A2>& y)
  1160. {
  1161. mpfr_mul_ui(a.data(), y.data(), x, GMP_RNDN);
  1162. }
  1163. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1164. inline void eval_multiply(mpfr_float_backend<D1, A1>& a, long x, const mpfr_float_backend<D2, A2>& y)
  1165. {
  1166. if (x < 0)
  1167. {
  1168. mpfr_mul_ui(a.data(), y.data(), boost::multiprecision::detail::unsigned_abs(x), GMP_RNDN);
  1169. mpfr_neg(a.data(), a.data(), GMP_RNDN);
  1170. }
  1171. else
  1172. mpfr_mul_ui(a.data(), y.data(), x, GMP_RNDN);
  1173. }
  1174. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2, unsigned D3>
  1175. inline void eval_divide(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, const mpfr_float_backend<D3>& y)
  1176. {
  1177. mpfr_div(a.data(), x.data(), y.data(), GMP_RNDN);
  1178. }
  1179. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1180. inline void eval_divide(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, unsigned long y)
  1181. {
  1182. mpfr_div_ui(a.data(), x.data(), y, GMP_RNDN);
  1183. }
  1184. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1185. inline void eval_divide(mpfr_float_backend<D1, A1>& a, const mpfr_float_backend<D2, A2>& x, long y)
  1186. {
  1187. if (y < 0)
  1188. {
  1189. mpfr_div_ui(a.data(), x.data(), boost::multiprecision::detail::unsigned_abs(y), GMP_RNDN);
  1190. a.negate();
  1191. }
  1192. else
  1193. mpfr_div_ui(a.data(), x.data(), y, GMP_RNDN);
  1194. }
  1195. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1196. inline void eval_divide(mpfr_float_backend<D1, A1>& a, unsigned long x, const mpfr_float_backend<D2, A2>& y)
  1197. {
  1198. mpfr_ui_div(a.data(), x, y.data(), GMP_RNDN);
  1199. }
  1200. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1201. inline void eval_divide(mpfr_float_backend<D1, A1>& a, long x, const mpfr_float_backend<D2, A2>& y)
  1202. {
  1203. if (x < 0)
  1204. {
  1205. mpfr_ui_div(a.data(), boost::multiprecision::detail::unsigned_abs(x), y.data(), GMP_RNDN);
  1206. mpfr_neg(a.data(), a.data(), GMP_RNDN);
  1207. }
  1208. else
  1209. mpfr_ui_div(a.data(), x, y.data(), GMP_RNDN);
  1210. }
  1211. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1212. inline bool eval_is_zero(const mpfr_float_backend<digits10, AllocationType>& val) BOOST_NOEXCEPT
  1213. {
  1214. return 0 != mpfr_zero_p(val.data());
  1215. }
  1216. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1217. inline int eval_get_sign(const mpfr_float_backend<digits10, AllocationType>& val) BOOST_NOEXCEPT
  1218. {
  1219. return mpfr_sgn(val.data());
  1220. }
  1221. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1222. inline void eval_convert_to(unsigned long* result, const mpfr_float_backend<digits10, AllocationType>& val)
  1223. {
  1224. if (mpfr_nan_p(val.data()))
  1225. {
  1226. BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert NaN to integer."));
  1227. }
  1228. *result = mpfr_get_ui(val.data(), GMP_RNDZ);
  1229. }
  1230. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1231. inline void eval_convert_to(long* result, const mpfr_float_backend<digits10, AllocationType>& val)
  1232. {
  1233. if (mpfr_nan_p(val.data()))
  1234. {
  1235. BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert NaN to integer."));
  1236. }
  1237. *result = mpfr_get_si(val.data(), GMP_RNDZ);
  1238. }
  1239. #ifdef _MPFR_H_HAVE_INTMAX_T
  1240. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1241. inline void eval_convert_to(boost::ulong_long_type* result, const mpfr_float_backend<digits10, AllocationType>& val)
  1242. {
  1243. if (mpfr_nan_p(val.data()))
  1244. {
  1245. BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert NaN to integer."));
  1246. }
  1247. *result = mpfr_get_uj(val.data(), GMP_RNDZ);
  1248. }
  1249. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1250. inline void eval_convert_to(boost::long_long_type* result, const mpfr_float_backend<digits10, AllocationType>& val)
  1251. {
  1252. if (mpfr_nan_p(val.data()))
  1253. {
  1254. BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert NaN to integer."));
  1255. }
  1256. *result = mpfr_get_sj(val.data(), GMP_RNDZ);
  1257. }
  1258. #endif
  1259. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1260. inline void eval_convert_to(float* result, const mpfr_float_backend<digits10, AllocationType>& val) BOOST_NOEXCEPT
  1261. {
  1262. *result = mpfr_get_flt(val.data(), GMP_RNDN);
  1263. }
  1264. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1265. inline void eval_convert_to(double* result, const mpfr_float_backend<digits10, AllocationType>& val) BOOST_NOEXCEPT
  1266. {
  1267. *result = mpfr_get_d(val.data(), GMP_RNDN);
  1268. }
  1269. template <unsigned digits10, mpfr_allocation_type AllocationType>
  1270. inline void eval_convert_to(long double* result, const mpfr_float_backend<digits10, AllocationType>& val) BOOST_NOEXCEPT
  1271. {
  1272. *result = mpfr_get_ld(val.data(), GMP_RNDN);
  1273. }
  1274. //
  1275. // Native non-member operations:
  1276. //
  1277. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1278. inline void eval_sqrt(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val)
  1279. {
  1280. mpfr_sqrt(result.data(), val.data(), GMP_RNDN);
  1281. }
  1282. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1283. inline void eval_abs(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val)
  1284. {
  1285. mpfr_abs(result.data(), val.data(), GMP_RNDN);
  1286. }
  1287. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1288. inline void eval_fabs(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val)
  1289. {
  1290. mpfr_abs(result.data(), val.data(), GMP_RNDN);
  1291. }
  1292. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1293. inline void eval_ceil(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val)
  1294. {
  1295. mpfr_ceil(result.data(), val.data());
  1296. }
  1297. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1298. inline void eval_floor(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val)
  1299. {
  1300. mpfr_floor(result.data(), val.data());
  1301. }
  1302. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1303. inline void eval_trunc(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val)
  1304. {
  1305. mpfr_trunc(result.data(), val.data());
  1306. }
  1307. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1308. inline void eval_ldexp(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val, long e)
  1309. {
  1310. if (e > 0)
  1311. mpfr_mul_2exp(result.data(), val.data(), e, GMP_RNDN);
  1312. else if (e < 0)
  1313. mpfr_div_2exp(result.data(), val.data(), -e, GMP_RNDN);
  1314. else
  1315. result = val;
  1316. }
  1317. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1318. inline void eval_frexp(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val, int* e)
  1319. {
  1320. long v;
  1321. mpfr_get_d_2exp(&v, val.data(), GMP_RNDN);
  1322. *e = v;
  1323. eval_ldexp(result, val, -v);
  1324. }
  1325. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1326. inline void eval_frexp(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& val, long* e)
  1327. {
  1328. mpfr_get_d_2exp(e, val.data(), GMP_RNDN);
  1329. return eval_ldexp(result, val, -*e);
  1330. }
  1331. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1332. inline int eval_fpclassify(const mpfr_float_backend<Digits10, AllocateType>& val) BOOST_NOEXCEPT
  1333. {
  1334. return mpfr_inf_p(val.data()) ? FP_INFINITE : mpfr_nan_p(val.data()) ? FP_NAN : mpfr_zero_p(val.data()) ? FP_ZERO : FP_NORMAL;
  1335. }
  1336. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1337. inline void eval_pow(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& b, const mpfr_float_backend<Digits10, AllocateType>& e)
  1338. {
  1339. if (mpfr_zero_p(b.data()) && mpfr_integer_p(e.data()) && (mpfr_signbit(e.data()) == 0) && mpfr_fits_ulong_p(e.data(), GMP_RNDN) && (mpfr_get_ui(e.data(), GMP_RNDN) & 1))
  1340. {
  1341. mpfr_set(result.data(), b.data(), GMP_RNDN);
  1342. }
  1343. else
  1344. mpfr_pow(result.data(), b.data(), e.data(), GMP_RNDN);
  1345. }
  1346. #ifdef BOOST_MSVC
  1347. //
  1348. // The enable_if usage below doesn't work with msvc - but only when
  1349. // certain other enable_if usages are defined first. It's a capricious
  1350. // and rather annoying compiler bug in other words....
  1351. //
  1352. #define BOOST_MP_ENABLE_IF_WORKAROUND (Digits10 || !Digits10)&&
  1353. #else
  1354. #define BOOST_MP_ENABLE_IF_WORKAROUND
  1355. #endif
  1356. template <unsigned Digits10, mpfr_allocation_type AllocateType, class Integer>
  1357. inline typename enable_if<mpl::and_<is_signed<Integer>, mpl::bool_<BOOST_MP_ENABLE_IF_WORKAROUND(sizeof(Integer) <= sizeof(long))> > >::type
  1358. eval_pow(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& b, const Integer& e)
  1359. {
  1360. mpfr_pow_si(result.data(), b.data(), e, GMP_RNDN);
  1361. }
  1362. template <unsigned Digits10, mpfr_allocation_type AllocateType, class Integer>
  1363. inline typename enable_if<mpl::and_<is_unsigned<Integer>, mpl::bool_<BOOST_MP_ENABLE_IF_WORKAROUND(sizeof(Integer) <= sizeof(long))> > >::type
  1364. eval_pow(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& b, const Integer& e)
  1365. {
  1366. mpfr_pow_ui(result.data(), b.data(), e, GMP_RNDN);
  1367. }
  1368. #undef BOOST_MP_ENABLE_IF_WORKAROUND
  1369. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1370. inline void eval_exp(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
  1371. {
  1372. mpfr_exp(result.data(), arg.data(), GMP_RNDN);
  1373. }
  1374. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1375. inline void eval_exp2(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
  1376. {
  1377. mpfr_exp2(result.data(), arg.data(), GMP_RNDN);
  1378. }
  1379. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1380. inline void eval_log(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
  1381. {
  1382. mpfr_log(result.data(), arg.data(), GMP_RNDN);
  1383. }
  1384. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1385. inline void eval_log10(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
  1386. {
  1387. mpfr_log10(result.data(), arg.data(), GMP_RNDN);
  1388. }
  1389. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1390. inline void eval_sin(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
  1391. {
  1392. mpfr_sin(result.data(), arg.data(), GMP_RNDN);
  1393. }
  1394. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1395. inline void eval_cos(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
  1396. {
  1397. mpfr_cos(result.data(), arg.data(), GMP_RNDN);
  1398. }
  1399. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1400. inline void eval_tan(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
  1401. {
  1402. mpfr_tan(result.data(), arg.data(), GMP_RNDN);
  1403. }
  1404. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1405. inline void eval_asin(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
  1406. {
  1407. mpfr_asin(result.data(), arg.data(), GMP_RNDN);
  1408. }
  1409. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1410. inline void eval_acos(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
  1411. {
  1412. mpfr_acos(result.data(), arg.data(), GMP_RNDN);
  1413. }
  1414. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1415. inline void eval_atan(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
  1416. {
  1417. mpfr_atan(result.data(), arg.data(), GMP_RNDN);
  1418. }
  1419. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1420. inline void eval_atan2(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg1, const mpfr_float_backend<Digits10, AllocateType>& arg2)
  1421. {
  1422. mpfr_atan2(result.data(), arg1.data(), arg2.data(), GMP_RNDN);
  1423. }
  1424. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1425. inline void eval_sinh(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
  1426. {
  1427. mpfr_sinh(result.data(), arg.data(), GMP_RNDN);
  1428. }
  1429. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1430. inline void eval_cosh(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
  1431. {
  1432. mpfr_cosh(result.data(), arg.data(), GMP_RNDN);
  1433. }
  1434. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1435. inline void eval_tanh(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
  1436. {
  1437. mpfr_tanh(result.data(), arg.data(), GMP_RNDN);
  1438. }
  1439. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1440. inline void eval_log2(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg)
  1441. {
  1442. mpfr_log2(result.data(), arg.data(), GMP_RNDN);
  1443. }
  1444. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1445. inline void eval_modf(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& arg, mpfr_float_backend<Digits10, AllocateType>* pipart)
  1446. {
  1447. if (0 == pipart)
  1448. {
  1449. mpfr_float_backend<Digits10, AllocateType> ipart;
  1450. mpfr_modf(ipart.data(), result.data(), arg.data(), GMP_RNDN);
  1451. }
  1452. else
  1453. {
  1454. mpfr_modf(pipart->data(), result.data(), arg.data(), GMP_RNDN);
  1455. }
  1456. }
  1457. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1458. inline void eval_remainder(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& a, const mpfr_float_backend<Digits10, AllocateType>& b)
  1459. {
  1460. mpfr_remainder(result.data(), a.data(), b.data(), GMP_RNDN);
  1461. }
  1462. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1463. inline void eval_remquo(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& a, const mpfr_float_backend<Digits10, AllocateType>& b, int* pi)
  1464. {
  1465. long l;
  1466. mpfr_remquo(result.data(), &l, a.data(), b.data(), GMP_RNDN);
  1467. if (pi)
  1468. *pi = l;
  1469. }
  1470. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1471. inline void eval_fmod(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& a, const mpfr_float_backend<Digits10, AllocateType>& b)
  1472. {
  1473. mpfr_fmod(result.data(), a.data(), b.data(), GMP_RNDN);
  1474. }
  1475. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1476. inline void eval_multiply_add(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& a, const mpfr_float_backend<Digits10, AllocateType>& b)
  1477. {
  1478. mpfr_fma(result.data(), a.data(), b.data(), result.data(), GMP_RNDN);
  1479. }
  1480. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1481. inline void eval_multiply_add(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& a, const mpfr_float_backend<Digits10, AllocateType>& b, const mpfr_float_backend<Digits10, AllocateType>& c)
  1482. {
  1483. mpfr_fma(result.data(), a.data(), b.data(), c.data(), GMP_RNDN);
  1484. }
  1485. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1486. inline void eval_multiply_subtract(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& a, const mpfr_float_backend<Digits10, AllocateType>& b)
  1487. {
  1488. mpfr_fms(result.data(), a.data(), b.data(), result.data(), GMP_RNDN);
  1489. result.negate();
  1490. }
  1491. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1492. inline void eval_multiply_subtract(mpfr_float_backend<Digits10, AllocateType>& result, const mpfr_float_backend<Digits10, AllocateType>& a, const mpfr_float_backend<Digits10, AllocateType>& b, const mpfr_float_backend<Digits10, AllocateType>& c)
  1493. {
  1494. mpfr_fms(result.data(), a.data(), b.data(), c.data(), GMP_RNDN);
  1495. }
  1496. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1497. inline int eval_signbit BOOST_PREVENT_MACRO_SUBSTITUTION(const mpfr_float_backend<Digits10, AllocateType>& arg)
  1498. {
  1499. return (arg.data()[0]._mpfr_sign < 0) ? 1 : 0;
  1500. }
  1501. template <unsigned Digits10, mpfr_allocation_type AllocateType>
  1502. inline std::size_t hash_value(const mpfr_float_backend<Digits10, AllocateType>& val)
  1503. {
  1504. std::size_t result = 0;
  1505. std::size_t len = val.data()[0]._mpfr_prec / mp_bits_per_limb;
  1506. if (val.data()[0]._mpfr_prec % mp_bits_per_limb)
  1507. ++len;
  1508. for (std::size_t i = 0; i < len; ++i)
  1509. boost::hash_combine(result, val.data()[0]._mpfr_d[i]);
  1510. boost::hash_combine(result, val.data()[0]._mpfr_exp);
  1511. boost::hash_combine(result, val.data()[0]._mpfr_sign);
  1512. return result;
  1513. }
  1514. } // namespace backends
  1515. #ifdef BOOST_NO_SFINAE_EXPR
  1516. namespace detail {
  1517. template <unsigned D1, unsigned D2, mpfr_allocation_type A1, mpfr_allocation_type A2>
  1518. struct is_explicitly_convertible<backends::mpfr_float_backend<D1, A1>, backends::mpfr_float_backend<D2, A2> > : public mpl::true_
  1519. {};
  1520. } // namespace detail
  1521. #endif
  1522. namespace detail {
  1523. template <>
  1524. struct is_variable_precision<backends::mpfr_float_backend<0> > : public true_type
  1525. {};
  1526. } // namespace detail
  1527. template <>
  1528. struct number_category<detail::canonical<mpfr_t, backends::mpfr_float_backend<0> >::type> : public mpl::int_<number_kind_floating_point>
  1529. {};
  1530. using boost::multiprecision::backends::mpfr_float_backend;
  1531. typedef number<mpfr_float_backend<50> > mpfr_float_50;
  1532. typedef number<mpfr_float_backend<100> > mpfr_float_100;
  1533. typedef number<mpfr_float_backend<500> > mpfr_float_500;
  1534. typedef number<mpfr_float_backend<1000> > mpfr_float_1000;
  1535. typedef number<mpfr_float_backend<0> > mpfr_float;
  1536. typedef number<mpfr_float_backend<50, allocate_stack> > static_mpfr_float_50;
  1537. typedef number<mpfr_float_backend<100, allocate_stack> > static_mpfr_float_100;
  1538. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1539. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> copysign BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& a, const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& b)
  1540. {
  1541. return (boost::multiprecision::signbit)(a) != (boost::multiprecision::signbit)(b) ? boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>(-a) : a;
  1542. }
  1543. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1544. inline boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates> copysign BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates>& a, const boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates>& b)
  1545. {
  1546. return (boost::multiprecision::signbit)(a) != (boost::multiprecision::signbit)(b) ? boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates>(-a) : a;
  1547. }
  1548. } // namespace multiprecision
  1549. namespace math {
  1550. using boost::multiprecision::copysign;
  1551. using boost::multiprecision::signbit;
  1552. namespace tools {
  1553. template <>
  1554. inline int digits<boost::multiprecision::mpfr_float>()
  1555. #ifdef BOOST_MATH_NOEXCEPT
  1556. BOOST_NOEXCEPT
  1557. #endif
  1558. {
  1559. return multiprecision::detail::digits10_2_2(boost::multiprecision::mpfr_float::default_precision());
  1560. }
  1561. template <>
  1562. inline int digits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, boost::multiprecision::et_off> >()
  1563. #ifdef BOOST_MATH_NOEXCEPT
  1564. BOOST_NOEXCEPT
  1565. #endif
  1566. {
  1567. return multiprecision::detail::digits10_2_2(boost::multiprecision::mpfr_float::default_precision());
  1568. }
  1569. template <>
  1570. inline boost::multiprecision::mpfr_float
  1571. max_value<boost::multiprecision::mpfr_float>()
  1572. {
  1573. boost::multiprecision::mpfr_float result(0.5);
  1574. mpfr_mul_2exp(result.backend().data(), result.backend().data(), mpfr_get_emax(), GMP_RNDN);
  1575. BOOST_ASSERT(mpfr_number_p(result.backend().data()));
  1576. return result;
  1577. }
  1578. template <>
  1579. inline boost::multiprecision::mpfr_float
  1580. min_value<boost::multiprecision::mpfr_float>()
  1581. {
  1582. boost::multiprecision::mpfr_float result(0.5);
  1583. mpfr_div_2exp(result.backend().data(), result.backend().data(), -mpfr_get_emin(), GMP_RNDN);
  1584. BOOST_ASSERT(mpfr_number_p(result.backend().data()));
  1585. return result;
  1586. }
  1587. template <>
  1588. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, boost::multiprecision::et_off>
  1589. max_value<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, boost::multiprecision::et_off> >()
  1590. {
  1591. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, boost::multiprecision::et_off> result(0.5);
  1592. mpfr_mul_2exp(result.backend().data(), result.backend().data(), mpfr_get_emax(), GMP_RNDN);
  1593. BOOST_ASSERT(mpfr_number_p(result.backend().data()));
  1594. return result;
  1595. }
  1596. template <>
  1597. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, boost::multiprecision::et_off>
  1598. min_value<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, boost::multiprecision::et_off> >()
  1599. {
  1600. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, boost::multiprecision::et_off> result(0.5);
  1601. mpfr_div_2exp(result.backend().data(), result.backend().data(), -mpfr_get_emin(), GMP_RNDN);
  1602. BOOST_ASSERT(mpfr_number_p(result.backend().data()));
  1603. return result;
  1604. }
  1605. template <>
  1606. inline int digits<boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float::backend_type> > >()
  1607. #ifdef BOOST_MATH_NOEXCEPT
  1608. BOOST_NOEXCEPT
  1609. #endif
  1610. {
  1611. return multiprecision::detail::digits10_2_2(boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float::backend_type> >::default_precision());
  1612. }
  1613. template <>
  1614. inline int digits<boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<0> >, boost::multiprecision::et_off> >()
  1615. #ifdef BOOST_MATH_NOEXCEPT
  1616. BOOST_NOEXCEPT
  1617. #endif
  1618. {
  1619. return multiprecision::detail::digits10_2_2(boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float::backend_type> >::default_precision());
  1620. }
  1621. template <>
  1622. inline boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float::backend_type> >
  1623. max_value<boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float::backend_type> > >()
  1624. {
  1625. return max_value<boost::multiprecision::mpfr_float>().backend();
  1626. }
  1627. template <>
  1628. inline boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float::backend_type> >
  1629. min_value<boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float::backend_type> > >()
  1630. {
  1631. return min_value<boost::multiprecision::mpfr_float>().backend();
  1632. }
  1633. template <>
  1634. inline boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<0> >, boost::multiprecision::et_off>
  1635. max_value<boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<0> >, boost::multiprecision::et_off> >()
  1636. {
  1637. return max_value<boost::multiprecision::mpfr_float>().backend();
  1638. }
  1639. template <>
  1640. inline boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<0> >, boost::multiprecision::et_off>
  1641. min_value<boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<0> >, boost::multiprecision::et_off> >()
  1642. {
  1643. return min_value<boost::multiprecision::mpfr_float>().backend();
  1644. }
  1645. } // namespace tools
  1646. namespace constants { namespace detail {
  1647. template <class T>
  1648. struct constant_pi;
  1649. template <class T>
  1650. struct constant_ln_two;
  1651. template <class T>
  1652. struct constant_euler;
  1653. template <class T>
  1654. struct constant_catalan;
  1655. namespace detail {
  1656. template <class T, int N>
  1657. struct mpfr_constant_initializer
  1658. {
  1659. static void force_instantiate()
  1660. {
  1661. init.force_instantiate();
  1662. }
  1663. private:
  1664. struct initializer
  1665. {
  1666. initializer()
  1667. {
  1668. T::get(boost::integral_constant<int, N>());
  1669. }
  1670. void force_instantiate() const {}
  1671. };
  1672. static const initializer init;
  1673. };
  1674. template <class T, int N>
  1675. typename mpfr_constant_initializer<T, N>::initializer const mpfr_constant_initializer<T, N>::init;
  1676. } // namespace detail
  1677. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1678. struct constant_pi<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >
  1679. {
  1680. typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result_type;
  1681. template <int N>
  1682. static inline const result_type& get(const boost::integral_constant<int, N>&)
  1683. {
  1684. detail::mpfr_constant_initializer<constant_pi<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >, N>::force_instantiate();
  1685. static result_type result;
  1686. static bool has_init = false;
  1687. if (!has_init)
  1688. {
  1689. mpfr_const_pi(result.backend().data(), GMP_RNDN);
  1690. has_init = true;
  1691. }
  1692. return result;
  1693. }
  1694. static inline const result_type get(const boost::integral_constant<int, 0>&)
  1695. {
  1696. result_type result;
  1697. mpfr_const_pi(result.backend().data(), GMP_RNDN);
  1698. return result;
  1699. }
  1700. };
  1701. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1702. struct constant_ln_two<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >
  1703. {
  1704. typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result_type;
  1705. template <int N>
  1706. static inline const result_type& get(const boost::integral_constant<int, N>&)
  1707. {
  1708. detail::mpfr_constant_initializer<constant_ln_two<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >, N>::force_instantiate();
  1709. static result_type result;
  1710. static bool init = false;
  1711. if (!init)
  1712. {
  1713. mpfr_const_log2(result.backend().data(), GMP_RNDN);
  1714. init = true;
  1715. }
  1716. return result;
  1717. }
  1718. static inline const result_type get(const boost::integral_constant<int, 0>&)
  1719. {
  1720. result_type result;
  1721. mpfr_const_log2(result.backend().data(), GMP_RNDN);
  1722. return result;
  1723. }
  1724. };
  1725. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1726. struct constant_euler<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >
  1727. {
  1728. typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result_type;
  1729. template <int N>
  1730. static inline const result_type& get(const boost::integral_constant<int, N>&)
  1731. {
  1732. detail::mpfr_constant_initializer<constant_euler<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >, N>::force_instantiate();
  1733. static result_type result;
  1734. static bool init = false;
  1735. if (!init)
  1736. {
  1737. mpfr_const_euler(result.backend().data(), GMP_RNDN);
  1738. init = true;
  1739. }
  1740. return result;
  1741. }
  1742. static inline const result_type get(const boost::integral_constant<int, 0>&)
  1743. {
  1744. result_type result;
  1745. mpfr_const_euler(result.backend().data(), GMP_RNDN);
  1746. return result;
  1747. }
  1748. };
  1749. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1750. struct constant_catalan<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >
  1751. {
  1752. typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result_type;
  1753. template <int N>
  1754. static inline const result_type& get(const boost::integral_constant<int, N>&)
  1755. {
  1756. detail::mpfr_constant_initializer<constant_catalan<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >, N>::force_instantiate();
  1757. static result_type result;
  1758. static bool init = false;
  1759. if (!init)
  1760. {
  1761. mpfr_const_catalan(result.backend().data(), GMP_RNDN);
  1762. init = true;
  1763. }
  1764. return result;
  1765. }
  1766. static inline const result_type get(const boost::integral_constant<int, 0>&)
  1767. {
  1768. result_type result;
  1769. mpfr_const_catalan(result.backend().data(), GMP_RNDN);
  1770. return result;
  1771. }
  1772. };
  1773. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1774. struct constant_pi<boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates> >
  1775. {
  1776. typedef boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates> result_type;
  1777. template <int N>
  1778. static inline const result_type& get(const boost::integral_constant<int, N>&)
  1779. {
  1780. detail::mpfr_constant_initializer<constant_pi<boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates> >, N>::force_instantiate();
  1781. static result_type result;
  1782. static bool has_init = false;
  1783. if (!has_init)
  1784. {
  1785. mpfr_const_pi(result.backend().value().data(), GMP_RNDN);
  1786. has_init = true;
  1787. }
  1788. return result;
  1789. }
  1790. static inline const result_type get(const boost::integral_constant<int, 0>&)
  1791. {
  1792. result_type result;
  1793. mpfr_const_pi(result.backend().value().data(), GMP_RNDN);
  1794. return result;
  1795. }
  1796. };
  1797. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1798. struct constant_ln_two<boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates> >
  1799. {
  1800. typedef boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates> result_type;
  1801. template <int N>
  1802. static inline const result_type& get(const boost::integral_constant<int, N>&)
  1803. {
  1804. detail::mpfr_constant_initializer<constant_ln_two<boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates> >, N>::force_instantiate();
  1805. static result_type result;
  1806. static bool init = false;
  1807. if (!init)
  1808. {
  1809. mpfr_const_log2(result.backend().value().data(), GMP_RNDN);
  1810. init = true;
  1811. }
  1812. return result;
  1813. }
  1814. static inline const result_type get(const boost::integral_constant<int, 0>&)
  1815. {
  1816. result_type result;
  1817. mpfr_const_log2(result.backend().value().data(), GMP_RNDN);
  1818. return result;
  1819. }
  1820. };
  1821. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1822. struct constant_euler<boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates> >
  1823. {
  1824. typedef boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates> result_type;
  1825. template <int N>
  1826. static inline const result_type& get(const boost::integral_constant<int, N>&)
  1827. {
  1828. detail::mpfr_constant_initializer<constant_euler<boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates> >, N>::force_instantiate();
  1829. static result_type result;
  1830. static bool init = false;
  1831. if (!init)
  1832. {
  1833. mpfr_const_euler(result.backend().value().data(), GMP_RNDN);
  1834. init = true;
  1835. }
  1836. return result;
  1837. }
  1838. static inline const result_type get(const boost::integral_constant<int, 0>&)
  1839. {
  1840. result_type result;
  1841. mpfr_const_euler(result.backend().value().data(), GMP_RNDN);
  1842. return result;
  1843. }
  1844. };
  1845. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1846. struct constant_catalan<boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates> >
  1847. {
  1848. typedef boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates> result_type;
  1849. template <int N>
  1850. static inline const result_type& get(const boost::integral_constant<int, N>&)
  1851. {
  1852. detail::mpfr_constant_initializer<constant_catalan<boost::multiprecision::number<boost::multiprecision::debug_adaptor<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType> >, ExpressionTemplates> >, N>::force_instantiate();
  1853. static result_type result;
  1854. static bool init = false;
  1855. if (!init)
  1856. {
  1857. mpfr_const_catalan(result.backend().value().data(), GMP_RNDN);
  1858. init = true;
  1859. }
  1860. return result;
  1861. }
  1862. static inline const result_type get(const boost::integral_constant<int, 0>&)
  1863. {
  1864. result_type result;
  1865. mpfr_const_catalan(result.backend().value().data(), GMP_RNDN);
  1866. return result;
  1867. }
  1868. };
  1869. }} // namespace constants::detail
  1870. } // namespace math
  1871. namespace multiprecision {
  1872. //
  1873. // Overloaded special functions which call native mpfr routines:
  1874. //
  1875. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1876. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> asinh BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  1877. {
  1878. boost::multiprecision::detail::scoped_default_precision<number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  1879. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  1880. mpfr_asinh(result.backend().data(), arg.backend().data(), GMP_RNDN);
  1881. return result;
  1882. }
  1883. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1884. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> acosh BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  1885. {
  1886. boost::multiprecision::detail::scoped_default_precision<number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  1887. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  1888. mpfr_acosh(result.backend().data(), arg.backend().data(), GMP_RNDN);
  1889. return result;
  1890. }
  1891. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1892. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> atanh BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  1893. {
  1894. boost::multiprecision::detail::scoped_default_precision<number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  1895. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  1896. mpfr_atanh(result.backend().data(), arg.backend().data(), GMP_RNDN);
  1897. return result;
  1898. }
  1899. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1900. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> cbrt BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  1901. {
  1902. boost::multiprecision::detail::scoped_default_precision<number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  1903. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  1904. mpfr_cbrt(result.backend().data(), arg.backend().data(), GMP_RNDN);
  1905. return result;
  1906. }
  1907. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1908. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> erf BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  1909. {
  1910. boost::multiprecision::detail::scoped_default_precision<number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  1911. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  1912. mpfr_erf(result.backend().data(), arg.backend().data(), GMP_RNDN);
  1913. return result;
  1914. }
  1915. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1916. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> erfc BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  1917. {
  1918. boost::multiprecision::detail::scoped_default_precision<number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  1919. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  1920. mpfr_erfc(result.backend().data(), arg.backend().data(), GMP_RNDN);
  1921. return result;
  1922. }
  1923. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1924. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> expm1 BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  1925. {
  1926. boost::multiprecision::detail::scoped_default_precision<number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  1927. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  1928. mpfr_expm1(result.backend().data(), arg.backend().data(), GMP_RNDN);
  1929. return result;
  1930. }
  1931. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1932. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> lgamma BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  1933. {
  1934. boost::multiprecision::detail::scoped_default_precision<number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  1935. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  1936. mpfr_lngamma(result.backend().data(), arg.backend().data(), GMP_RNDN);
  1937. return result;
  1938. }
  1939. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1940. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> tgamma BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  1941. {
  1942. boost::multiprecision::detail::scoped_default_precision<number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  1943. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  1944. mpfr_gamma(result.backend().data(), arg.backend().data(), GMP_RNDN);
  1945. return result;
  1946. }
  1947. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1948. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> log1p BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  1949. {
  1950. boost::multiprecision::detail::scoped_default_precision<number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  1951. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  1952. mpfr_log1p(result.backend().data(), arg.backend().data(), GMP_RNDN);
  1953. return result;
  1954. }
  1955. } // namespace multiprecision
  1956. namespace math {
  1957. //
  1958. // Overloaded special functions which call native mpfr routines:
  1959. //
  1960. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates, class Policy>
  1961. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> asinh BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg, const Policy&)
  1962. {
  1963. boost::multiprecision::detail::scoped_default_precision<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  1964. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  1965. mpfr_asinh(result.backend().data(), arg.backend().data(), GMP_RNDN);
  1966. if (mpfr_inf_p(result.backend().data()))
  1967. return policies::raise_overflow_error<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >("asinh<%1%>(%1%)", 0, Policy());
  1968. if (mpfr_nan_p(result.backend().data()))
  1969. return policies::raise_evaluation_error("asinh<%1%>(%1%)", "Unknown error, result is a NaN", result, Policy());
  1970. return result;
  1971. }
  1972. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1973. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> asinh BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  1974. {
  1975. return asinh(arg, policies::policy<>());
  1976. }
  1977. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates, class Policy>
  1978. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> acosh BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg, const Policy&)
  1979. {
  1980. boost::multiprecision::detail::scoped_default_precision<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  1981. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  1982. mpfr_acosh(result.backend().data(), arg.backend().data(), GMP_RNDN);
  1983. if (mpfr_inf_p(result.backend().data()))
  1984. return policies::raise_overflow_error<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >("acosh<%1%>(%1%)", 0, Policy());
  1985. if (mpfr_nan_p(result.backend().data()))
  1986. return policies::raise_evaluation_error("acosh<%1%>(%1%)", "Unknown error, result is a NaN", result, Policy());
  1987. return result;
  1988. }
  1989. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  1990. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> acosh BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  1991. {
  1992. return acosh(arg, policies::policy<>());
  1993. }
  1994. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates, class Policy>
  1995. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> atanh BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg, const Policy& )
  1996. {
  1997. boost::multiprecision::detail::scoped_default_precision<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  1998. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  1999. mpfr_atanh(result.backend().data(), arg.backend().data(), GMP_RNDN);
  2000. if (mpfr_inf_p(result.backend().data()))
  2001. return policies::raise_overflow_error<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >("atanh<%1%>(%1%)", 0, Policy());
  2002. if (mpfr_nan_p(result.backend().data()))
  2003. return policies::raise_evaluation_error("atanh<%1%>(%1%)", "Unknown error, result is a NaN", result, Policy());
  2004. return result;
  2005. }
  2006. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2007. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> atanh BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  2008. {
  2009. return atanh(arg, policies::policy<>());
  2010. }
  2011. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates, class Policy>
  2012. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> cbrt BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg, const Policy&)
  2013. {
  2014. boost::multiprecision::detail::scoped_default_precision<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  2015. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  2016. mpfr_cbrt(result.backend().data(), arg.backend().data(), GMP_RNDN);
  2017. if (mpfr_inf_p(result.backend().data()))
  2018. return policies::raise_overflow_error<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >("cbrt<%1%>(%1%)", 0, Policy());
  2019. if (mpfr_nan_p(result.backend().data()))
  2020. return policies::raise_evaluation_error("cbrt<%1%>(%1%)", "Unknown error, result is a NaN", result, Policy());
  2021. return result;
  2022. }
  2023. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2024. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> cbrt BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  2025. {
  2026. return cbrt(arg, policies::policy<>());
  2027. }
  2028. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates, class Policy>
  2029. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> erf BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg, const Policy& pol)
  2030. {
  2031. boost::multiprecision::detail::scoped_default_precision<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  2032. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  2033. mpfr_erf(result.backend().data(), arg.backend().data(), GMP_RNDN);
  2034. if (mpfr_inf_p(result.backend().data()))
  2035. return policies::raise_overflow_error<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >("erf<%1%>(%1%)", 0, pol);
  2036. if (mpfr_nan_p(result.backend().data()))
  2037. return policies::raise_evaluation_error("erf<%1%>(%1%)", "Unknown error, result is a NaN", result, pol);
  2038. return result;
  2039. }
  2040. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2041. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> erf BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  2042. {
  2043. return erf(arg, policies::policy<>());
  2044. }
  2045. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates, class Policy>
  2046. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> erfc BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg, const Policy& pol)
  2047. {
  2048. boost::multiprecision::detail::scoped_default_precision<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  2049. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  2050. mpfr_erfc(result.backend().data(), arg.backend().data(), GMP_RNDN);
  2051. if (mpfr_inf_p(result.backend().data()))
  2052. return policies::raise_overflow_error<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >("erfc<%1%>(%1%)", 0, pol);
  2053. if (mpfr_nan_p(result.backend().data()))
  2054. return policies::raise_evaluation_error("erfc<%1%>(%1%)", "Unknown error, result is a NaN", result, pol);
  2055. return result;
  2056. }
  2057. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2058. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> erfc BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  2059. {
  2060. return erfc(arg, policies::policy<>());
  2061. }
  2062. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates, class Policy>
  2063. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> expm1 BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg, const Policy& pol)
  2064. {
  2065. boost::multiprecision::detail::scoped_default_precision<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  2066. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  2067. mpfr_expm1(result.backend().data(), arg.backend().data(), GMP_RNDN);
  2068. if (mpfr_inf_p(result.backend().data()))
  2069. return policies::raise_overflow_error<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >("expm1<%1%>(%1%)", 0, pol);
  2070. if (mpfr_nan_p(result.backend().data()))
  2071. return policies::raise_evaluation_error("expm1<%1%>(%1%)", "Unknown error, result is a NaN", result, pol);
  2072. return result;
  2073. }
  2074. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2075. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> exm1 BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  2076. {
  2077. return expm1(arg, policies::policy<>());
  2078. }
  2079. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates, class Policy>
  2080. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> lgamma BOOST_PREVENT_MACRO_SUBSTITUTION(boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> arg, int* sign, const Policy& pol)
  2081. {
  2082. boost::multiprecision::detail::scoped_default_precision<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  2083. (void)precision_guard; // warning suppression
  2084. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  2085. if (arg > 0)
  2086. {
  2087. mpfr_lngamma(result.backend().data(), arg.backend().data(), GMP_RNDN);
  2088. if (sign)
  2089. *sign = 1;
  2090. }
  2091. else
  2092. {
  2093. if (floor(arg) == arg)
  2094. return policies::raise_pole_error<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >(
  2095. "lgamma<%1%>", "Evaluation of lgamma at a negative integer %1%.", arg, pol);
  2096. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> t = detail::sinpx(arg);
  2097. arg = -arg;
  2098. if (t < 0)
  2099. {
  2100. t = -t;
  2101. }
  2102. result = boost::multiprecision::log(boost::math::constants::pi<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >()) - lgamma(arg, 0, pol) - boost::multiprecision::log(t);
  2103. if (sign)
  2104. {
  2105. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> phase = 1 - arg;
  2106. phase = floor(phase) / 2;
  2107. if (floor(phase) == phase)
  2108. *sign = -1;
  2109. else
  2110. *sign = 1;
  2111. }
  2112. }
  2113. if (mpfr_inf_p(result.backend().data()))
  2114. return policies::raise_overflow_error<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >("lgamma<%1%>(%1%)", 0, pol);
  2115. if (mpfr_nan_p(result.backend().data()))
  2116. return policies::raise_evaluation_error("lgamma<%1%>(%1%)", "Unknown error, result is a NaN", result, pol);
  2117. return result;
  2118. }
  2119. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2120. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> lgamma BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg, int* sign)
  2121. {
  2122. return lgamma(arg, sign, policies::policy<>());
  2123. }
  2124. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates, class Policy>
  2125. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> lgamma BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg, const Policy& pol)
  2126. {
  2127. return lgamma(arg, 0, pol);
  2128. }
  2129. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2130. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> lgamma BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  2131. {
  2132. return lgamma(arg, 0, policies::policy<>());
  2133. }
  2134. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates, class Policy>
  2135. inline typename boost::enable_if_c<boost::math::policies::is_policy<Policy>::value, boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::type tgamma BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg, const Policy& pol)
  2136. {
  2137. boost::multiprecision::detail::scoped_default_precision<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  2138. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  2139. mpfr_gamma(result.backend().data(), arg.backend().data(), GMP_RNDN);
  2140. if (mpfr_inf_p(result.backend().data()))
  2141. return policies::raise_overflow_error<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >("tgamma<%1%>(%1%)", 0, pol);
  2142. if (mpfr_nan_p(result.backend().data()))
  2143. return policies::raise_evaluation_error("tgamma<%1%>(%1%)", "Unknown error, result is a NaN", result, pol);
  2144. return result;
  2145. }
  2146. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2147. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> tgamma BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  2148. {
  2149. return tgamma(arg, policies::policy<>());
  2150. }
  2151. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates, class Policy>
  2152. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> log1p BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg, const Policy& pol)
  2153. {
  2154. boost::multiprecision::detail::scoped_default_precision<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> > precision_guard(arg);
  2155. boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> result;
  2156. mpfr_log1p(result.backend().data(), arg.backend().data(), GMP_RNDN);
  2157. if (mpfr_inf_p(result.backend().data()))
  2158. return policies::raise_overflow_error<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >("log1p<%1%>(%1%)", 0, pol);
  2159. if (mpfr_nan_p(result.backend().data()))
  2160. return policies::raise_evaluation_error("log1p<%1%>(%1%)", "Unknown error, result is a NaN", result, pol);
  2161. return result;
  2162. }
  2163. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2164. inline boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> log1p BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates>& arg)
  2165. {
  2166. return log1p(arg, policies::policy<>());
  2167. }
  2168. } // namespace math
  2169. } // namespace boost
  2170. namespace std {
  2171. //
  2172. // numeric_limits [partial] specializations for the types declared in this header:
  2173. //
  2174. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2175. class numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >
  2176. {
  2177. typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> number_type;
  2178. public:
  2179. BOOST_STATIC_CONSTEXPR bool is_specialized = true;
  2180. static number_type(min)()
  2181. {
  2182. initializer.do_nothing();
  2183. static std::pair<bool, number_type> value;
  2184. if (!value.first)
  2185. {
  2186. value.first = true;
  2187. value.second = 0.5;
  2188. mpfr_div_2exp(value.second.backend().data(), value.second.backend().data(), -mpfr_get_emin(), GMP_RNDN);
  2189. }
  2190. return value.second;
  2191. }
  2192. static number_type(max)()
  2193. {
  2194. initializer.do_nothing();
  2195. static std::pair<bool, number_type> value;
  2196. if (!value.first)
  2197. {
  2198. value.first = true;
  2199. value.second = 0.5;
  2200. mpfr_mul_2exp(value.second.backend().data(), value.second.backend().data(), mpfr_get_emax(), GMP_RNDN);
  2201. }
  2202. return value.second;
  2203. }
  2204. BOOST_STATIC_CONSTEXPR number_type lowest()
  2205. {
  2206. return -(max)();
  2207. }
  2208. BOOST_STATIC_CONSTEXPR int digits = static_cast<int>((Digits10 * 1000L) / 301L + ((Digits10 * 1000L) % 301 ? 2 : 1));
  2209. BOOST_STATIC_CONSTEXPR int digits10 = Digits10;
  2210. // Is this really correct???
  2211. BOOST_STATIC_CONSTEXPR int max_digits10 = Digits10 + 3;
  2212. BOOST_STATIC_CONSTEXPR bool is_signed = true;
  2213. BOOST_STATIC_CONSTEXPR bool is_integer = false;
  2214. BOOST_STATIC_CONSTEXPR bool is_exact = false;
  2215. BOOST_STATIC_CONSTEXPR int radix = 2;
  2216. static number_type epsilon()
  2217. {
  2218. initializer.do_nothing();
  2219. static std::pair<bool, number_type> value;
  2220. if (!value.first)
  2221. {
  2222. value.first = true;
  2223. value.second = 1;
  2224. mpfr_div_2exp(value.second.backend().data(), value.second.backend().data(), std::numeric_limits<number_type>::digits - 1, GMP_RNDN);
  2225. }
  2226. return value.second;
  2227. }
  2228. // What value should this be????
  2229. static number_type round_error()
  2230. {
  2231. // returns epsilon/2
  2232. initializer.do_nothing();
  2233. static std::pair<bool, number_type> value;
  2234. if (!value.first)
  2235. {
  2236. value.first = true;
  2237. value.second = 1;
  2238. mpfr_div_2exp(value.second.backend().data(), value.second.backend().data(), 1, GMP_RNDN);
  2239. }
  2240. return value.second;
  2241. }
  2242. BOOST_STATIC_CONSTEXPR long min_exponent = MPFR_EMIN_DEFAULT;
  2243. BOOST_STATIC_CONSTEXPR long min_exponent10 = (MPFR_EMIN_DEFAULT / 1000) * 301L;
  2244. BOOST_STATIC_CONSTEXPR long max_exponent = MPFR_EMAX_DEFAULT;
  2245. BOOST_STATIC_CONSTEXPR long max_exponent10 = (MPFR_EMAX_DEFAULT / 1000) * 301L;
  2246. BOOST_STATIC_CONSTEXPR bool has_infinity = true;
  2247. BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = true;
  2248. BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false;
  2249. BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent;
  2250. BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false;
  2251. static number_type infinity()
  2252. {
  2253. // returns epsilon/2
  2254. initializer.do_nothing();
  2255. static std::pair<bool, number_type> value;
  2256. if (!value.first)
  2257. {
  2258. value.first = true;
  2259. value.second = 1;
  2260. mpfr_set_inf(value.second.backend().data(), 1);
  2261. }
  2262. return value.second;
  2263. }
  2264. static number_type quiet_NaN()
  2265. {
  2266. // returns epsilon/2
  2267. initializer.do_nothing();
  2268. static std::pair<bool, number_type> value;
  2269. if (!value.first)
  2270. {
  2271. value.first = true;
  2272. value.second = 1;
  2273. mpfr_set_nan(value.second.backend().data());
  2274. }
  2275. return value.second;
  2276. }
  2277. BOOST_STATIC_CONSTEXPR number_type signaling_NaN()
  2278. {
  2279. return number_type(0);
  2280. }
  2281. BOOST_STATIC_CONSTEXPR number_type denorm_min() { return number_type(0); }
  2282. BOOST_STATIC_CONSTEXPR bool is_iec559 = false;
  2283. BOOST_STATIC_CONSTEXPR bool is_bounded = true;
  2284. BOOST_STATIC_CONSTEXPR bool is_modulo = false;
  2285. BOOST_STATIC_CONSTEXPR bool traps = true;
  2286. BOOST_STATIC_CONSTEXPR bool tinyness_before = false;
  2287. BOOST_STATIC_CONSTEXPR float_round_style round_style = round_to_nearest;
  2288. private:
  2289. struct data_initializer
  2290. {
  2291. data_initializer()
  2292. {
  2293. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<digits10, AllocateType> > >::epsilon();
  2294. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<digits10, AllocateType> > >::round_error();
  2295. (std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<digits10, AllocateType> > >::min)();
  2296. (std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<digits10, AllocateType> > >::max)();
  2297. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<digits10, AllocateType> > >::infinity();
  2298. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<digits10, AllocateType> > >::quiet_NaN();
  2299. }
  2300. void do_nothing() const {}
  2301. };
  2302. static const data_initializer initializer;
  2303. };
  2304. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2305. const typename numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::data_initializer numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::initializer;
  2306. #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
  2307. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2308. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::digits;
  2309. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2310. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::digits10;
  2311. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2312. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::max_digits10;
  2313. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2314. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::is_signed;
  2315. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2316. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::is_integer;
  2317. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2318. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::is_exact;
  2319. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2320. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::radix;
  2321. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2322. BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::min_exponent;
  2323. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2324. BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::min_exponent10;
  2325. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2326. BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::max_exponent;
  2327. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2328. BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::max_exponent10;
  2329. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2330. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::has_infinity;
  2331. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2332. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::has_quiet_NaN;
  2333. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2334. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::has_signaling_NaN;
  2335. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2336. BOOST_CONSTEXPR_OR_CONST float_denorm_style numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::has_denorm;
  2337. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2338. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::has_denorm_loss;
  2339. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2340. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::is_iec559;
  2341. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2342. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::is_bounded;
  2343. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2344. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::is_modulo;
  2345. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2346. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::traps;
  2347. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2348. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::tinyness_before;
  2349. template <unsigned Digits10, boost::multiprecision::mpfr_allocation_type AllocateType, boost::multiprecision::expression_template_option ExpressionTemplates>
  2350. BOOST_CONSTEXPR_OR_CONST float_round_style numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10, AllocateType>, ExpressionTemplates> >::round_style;
  2351. #endif
  2352. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2353. class numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >
  2354. {
  2355. typedef boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> number_type;
  2356. public:
  2357. BOOST_STATIC_CONSTEXPR bool is_specialized = false;
  2358. static number_type(min)()
  2359. {
  2360. number_type value(0.5);
  2361. mpfr_div_2exp(value.backend().data(), value.backend().data(), -mpfr_get_emin(), GMP_RNDN);
  2362. return value;
  2363. }
  2364. static number_type(max)()
  2365. {
  2366. number_type value(0.5);
  2367. mpfr_mul_2exp(value.backend().data(), value.backend().data(), mpfr_get_emax(), GMP_RNDN);
  2368. return value;
  2369. }
  2370. static number_type lowest()
  2371. {
  2372. return -(max)();
  2373. }
  2374. BOOST_STATIC_CONSTEXPR int digits = INT_MAX;
  2375. BOOST_STATIC_CONSTEXPR int digits10 = INT_MAX;
  2376. BOOST_STATIC_CONSTEXPR int max_digits10 = INT_MAX;
  2377. BOOST_STATIC_CONSTEXPR bool is_signed = true;
  2378. BOOST_STATIC_CONSTEXPR bool is_integer = false;
  2379. BOOST_STATIC_CONSTEXPR bool is_exact = false;
  2380. BOOST_STATIC_CONSTEXPR int radix = 2;
  2381. static number_type epsilon()
  2382. {
  2383. number_type value(1);
  2384. mpfr_div_2exp(value.backend().data(), value.backend().data(), boost::multiprecision::detail::digits10_2_2(number_type::default_precision()) - 1, GMP_RNDN);
  2385. return value;
  2386. }
  2387. static number_type round_error()
  2388. {
  2389. return epsilon() / 2;
  2390. }
  2391. BOOST_STATIC_CONSTEXPR long min_exponent = MPFR_EMIN_DEFAULT;
  2392. BOOST_STATIC_CONSTEXPR long min_exponent10 = (MPFR_EMIN_DEFAULT / 1000) * 301L;
  2393. BOOST_STATIC_CONSTEXPR long max_exponent = MPFR_EMAX_DEFAULT;
  2394. BOOST_STATIC_CONSTEXPR long max_exponent10 = (MPFR_EMAX_DEFAULT / 1000) * 301L;
  2395. BOOST_STATIC_CONSTEXPR bool has_infinity = true;
  2396. BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = true;
  2397. BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false;
  2398. BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent;
  2399. BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false;
  2400. static number_type infinity()
  2401. {
  2402. number_type value;
  2403. mpfr_set_inf(value.backend().data(), 1);
  2404. return value;
  2405. }
  2406. static number_type quiet_NaN()
  2407. {
  2408. number_type value;
  2409. mpfr_set_nan(value.backend().data());
  2410. return value;
  2411. }
  2412. static number_type signaling_NaN() { return number_type(0); }
  2413. static number_type denorm_min() { return number_type(0); }
  2414. BOOST_STATIC_CONSTEXPR bool is_iec559 = false;
  2415. BOOST_STATIC_CONSTEXPR bool is_bounded = true;
  2416. BOOST_STATIC_CONSTEXPR bool is_modulo = false;
  2417. BOOST_STATIC_CONSTEXPR bool traps = false;
  2418. BOOST_STATIC_CONSTEXPR bool tinyness_before = false;
  2419. BOOST_STATIC_CONSTEXPR float_round_style round_style = round_toward_zero;
  2420. };
  2421. #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
  2422. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2423. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::digits;
  2424. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2425. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::digits10;
  2426. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2427. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::max_digits10;
  2428. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2429. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::is_signed;
  2430. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2431. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::is_integer;
  2432. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2433. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::is_exact;
  2434. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2435. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::radix;
  2436. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2437. BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::min_exponent;
  2438. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2439. BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::min_exponent10;
  2440. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2441. BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::max_exponent;
  2442. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2443. BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::max_exponent10;
  2444. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2445. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::has_infinity;
  2446. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2447. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::has_quiet_NaN;
  2448. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2449. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::has_signaling_NaN;
  2450. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2451. BOOST_CONSTEXPR_OR_CONST float_denorm_style numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::has_denorm;
  2452. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2453. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::has_denorm_loss;
  2454. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2455. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::is_iec559;
  2456. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2457. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::is_bounded;
  2458. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2459. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::is_modulo;
  2460. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2461. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::traps;
  2462. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2463. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::tinyness_before;
  2464. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  2465. BOOST_CONSTEXPR_OR_CONST float_round_style numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<0>, ExpressionTemplates> >::round_style;
  2466. #endif
  2467. } // namespace std
  2468. #endif