mpfr.hpp 125 KB

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