mpfr.hpp 100 KB

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