mpfr.hpp 125 KB

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