mpfi.hpp 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558
  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_MPFI_HPP
  6. #define BOOST_MATH_BN_MPFI_HPP
  7. #include <boost/multiprecision/number.hpp>
  8. #include <boost/math/special_functions/fpclassify.hpp>
  9. #include <boost/cstdint.hpp>
  10. #include <boost/multiprecision/detail/big_lanczos.hpp>
  11. #include <boost/multiprecision/detail/digits.hpp>
  12. #include <boost/multiprecision/mpfr.hpp>
  13. #include <boost/math/constants/constants.hpp>
  14. #include <mpfi.h>
  15. #include <cmath>
  16. #include <algorithm>
  17. namespace boost{
  18. namespace multiprecision{
  19. namespace backends{
  20. template <unsigned digits10>
  21. struct mpfi_float_backend;
  22. } // namespace backends
  23. template <unsigned digits10>
  24. struct number_category<backends::mpfi_float_backend<digits10> > : public mpl::int_<number_kind_floating_point>{};
  25. struct interval_error : public std::runtime_error
  26. {
  27. interval_error(const std::string& s) : std::runtime_error(s) {}
  28. };
  29. namespace backends{
  30. namespace detail{
  31. inline int mpfi_sgn(mpfi_srcptr p)
  32. {
  33. if(mpfi_is_zero(p))
  34. return 0;
  35. if(mpfi_is_strictly_pos(p))
  36. return 1;
  37. if(mpfi_is_strictly_neg(p))
  38. return -1;
  39. BOOST_THROW_EXCEPTION(interval_error("Sign of interval is ambiguous."));
  40. }
  41. template <unsigned digits10>
  42. struct mpfi_float_imp;
  43. template <unsigned digits10>
  44. struct mpfi_float_imp
  45. {
  46. #ifdef BOOST_HAS_LONG_LONG
  47. typedef mpl::list<long, boost::long_long_type> signed_types;
  48. typedef mpl::list<unsigned long, boost::ulong_long_type> unsigned_types;
  49. #else
  50. typedef mpl::list<long> signed_types;
  51. typedef mpl::list<unsigned long> unsigned_types;
  52. #endif
  53. typedef mpl::list<double, long double> float_types;
  54. typedef long exponent_type;
  55. mpfi_float_imp()
  56. {
  57. mpfi_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
  58. }
  59. mpfi_float_imp(unsigned prec)
  60. {
  61. mpfi_init2(m_data, prec);
  62. }
  63. mpfi_float_imp(const mpfi_float_imp& o)
  64. {
  65. mpfi_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
  66. if(o.m_data[0].left._mpfr_d)
  67. mpfi_set(m_data, o.m_data);
  68. }
  69. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  70. mpfi_float_imp(mpfi_float_imp&& o) BOOST_NOEXCEPT
  71. {
  72. m_data[0] = o.m_data[0];
  73. o.m_data[0].left._mpfr_d = 0;
  74. }
  75. #endif
  76. mpfi_float_imp& operator = (const mpfi_float_imp& o)
  77. {
  78. if(m_data[0].left._mpfr_d == 0)
  79. mpfi_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
  80. if(o.m_data[0].left._mpfr_d)
  81. mpfi_set(m_data, o.m_data);
  82. return *this;
  83. }
  84. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  85. mpfi_float_imp& operator = (mpfi_float_imp&& o) BOOST_NOEXCEPT
  86. {
  87. mpfi_swap(m_data, o.m_data);
  88. return *this;
  89. }
  90. #endif
  91. #ifdef BOOST_HAS_LONG_LONG
  92. #ifdef _MPFR_H_HAVE_INTMAX_T
  93. mpfi_float_imp& operator = (boost::ulong_long_type i)
  94. {
  95. if(m_data[0].left._mpfr_d == 0)
  96. mpfi_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
  97. mpfr_set_uj(left_data(), i, GMP_RNDD);
  98. mpfr_set_uj(right_data(), i, GMP_RNDU);
  99. return *this;
  100. }
  101. mpfi_float_imp& operator = (boost::long_long_type i)
  102. {
  103. if(m_data[0].left._mpfr_d == 0)
  104. mpfi_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
  105. mpfr_set_sj(left_data(), i, GMP_RNDD);
  106. mpfr_set_sj(right_data(), i, GMP_RNDU);
  107. return *this;
  108. }
  109. #else
  110. mpfi_float_imp& operator = (boost::ulong_long_type i)
  111. {
  112. if(m_data[0].left._mpfr_d == 0)
  113. mpfi_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
  114. boost::ulong_long_type mask = ((((1uLL << (std::numeric_limits<unsigned long>::digits - 1)) - 1) << 1) | 1u);
  115. unsigned shift = 0;
  116. mpfi_t t;
  117. mpfi_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))));
  118. mpfi_set_ui(m_data, 0);
  119. while(i)
  120. {
  121. mpfi_set_ui(t, static_cast<unsigned long>(i & mask));
  122. if(shift)
  123. mpfi_mul_2exp(t, t, shift);
  124. mpfi_add(m_data, m_data, t);
  125. shift += std::numeric_limits<unsigned long>::digits;
  126. i >>= std::numeric_limits<unsigned long>::digits;
  127. }
  128. mpfi_clear(t);
  129. return *this;
  130. }
  131. mpfi_float_imp& operator = (boost::long_long_type i)
  132. {
  133. if(m_data[0].left._mpfr_d == 0)
  134. mpfi_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
  135. bool neg = i < 0;
  136. *this = boost::multiprecision::detail::unsigned_abs(i);
  137. if(neg)
  138. mpfi_neg(m_data, m_data);
  139. return *this;
  140. }
  141. #endif
  142. #endif
  143. mpfi_float_imp& operator = (unsigned long i)
  144. {
  145. if(m_data[0].left._mpfr_d == 0)
  146. mpfi_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
  147. mpfi_set_ui(m_data, i);
  148. return *this;
  149. }
  150. mpfi_float_imp& operator = (long i)
  151. {
  152. if(m_data[0].left._mpfr_d == 0)
  153. mpfi_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
  154. mpfi_set_si(m_data, i);
  155. return *this;
  156. }
  157. mpfi_float_imp& operator = (double d)
  158. {
  159. if(m_data[0].left._mpfr_d == 0)
  160. mpfi_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
  161. mpfi_set_d(m_data, d);
  162. return *this;
  163. }
  164. mpfi_float_imp& operator = (long double a)
  165. {
  166. if(m_data[0].left._mpfr_d == 0)
  167. mpfi_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
  168. mpfr_set_ld(left_data(), a, GMP_RNDD);
  169. mpfr_set_ld(right_data(), a, GMP_RNDU);
  170. return *this;
  171. }
  172. mpfi_float_imp& operator = (const char* s)
  173. {
  174. using default_ops::eval_fpclassify;
  175. if(m_data[0].left._mpfr_d == 0)
  176. mpfi_init2(m_data, multiprecision::detail::digits10_2_2(digits10 ? digits10 : get_default_precision()));
  177. if(s && (*s == '{'))
  178. {
  179. mpfr_float_backend<digits10> a, b;
  180. std::string part;
  181. const char* p = ++s;
  182. while(*p && (*p != ',') && (*p != '}'))
  183. ++p;
  184. part.assign(s + 1, p);
  185. a = part.c_str();
  186. s = p;
  187. if(*p && (*p != '}'))
  188. {
  189. ++p;
  190. while(*p && (*p != ',') && (*p != '}'))
  191. ++p;
  192. part.assign(s + 1, p);
  193. }
  194. else
  195. part.erase();
  196. b = part.c_str();
  197. if(eval_fpclassify(a) == (int)FP_NAN)
  198. {
  199. mpfi_set_fr(this->data(), a.data());
  200. }
  201. else if(eval_fpclassify(b) == (int)FP_NAN)
  202. {
  203. mpfi_set_fr(this->data(), b.data());
  204. }
  205. else
  206. {
  207. if(a.compare(b) > 0)
  208. {
  209. BOOST_THROW_EXCEPTION(std::runtime_error("Attempt to create interval with invalid range (start is greater than end)."));
  210. }
  211. mpfi_interv_fr(m_data, a.data(), b.data());
  212. }
  213. }
  214. else if(mpfi_set_str(m_data, s, 10) != 0)
  215. {
  216. BOOST_THROW_EXCEPTION(std::runtime_error(std::string("Unable to parse string \"") + s + std::string("\"as a valid floating point number.")));
  217. }
  218. return *this;
  219. }
  220. void swap(mpfi_float_imp& o) BOOST_NOEXCEPT
  221. {
  222. mpfi_swap(m_data, o.m_data);
  223. }
  224. std::string str(std::streamsize digits, std::ios_base::fmtflags f)const
  225. {
  226. BOOST_ASSERT(m_data[0].left._mpfr_d);
  227. mpfr_float_backend<digits10> a, b;
  228. mpfi_get_left(a.data(), m_data);
  229. mpfi_get_right(b.data(), m_data);
  230. if(a.compare(b) == 0)
  231. return a.str(digits, f);
  232. return "{" + a.str(digits, f) + "," + b.str(digits, f) + "}";
  233. }
  234. ~mpfi_float_imp() BOOST_NOEXCEPT
  235. {
  236. if(m_data[0].left._mpfr_d)
  237. mpfi_clear(m_data);
  238. }
  239. void negate() BOOST_NOEXCEPT
  240. {
  241. BOOST_ASSERT(m_data[0].left._mpfr_d);
  242. mpfi_neg(m_data, m_data);
  243. }
  244. int compare(const mpfi_float_imp& o)const BOOST_NOEXCEPT
  245. {
  246. BOOST_ASSERT(m_data[0].left._mpfr_d && o.m_data[0].left._mpfr_d);
  247. if(mpfr_cmp(right_data(), o.left_data()) < 0)
  248. return -1;
  249. if(mpfr_cmp(left_data(), o.right_data()) > 0)
  250. return 1;
  251. if((mpfr_cmp(left_data(), o.left_data()) == 0) && (mpfr_cmp(right_data(), o.right_data()) == 0))
  252. return 0;
  253. BOOST_THROW_EXCEPTION(interval_error("Ambiguous comparison between two values."));
  254. return 0;
  255. }
  256. template <class V>
  257. int compare(V v)const BOOST_NOEXCEPT
  258. {
  259. mpfi_float_imp d;
  260. d = v;
  261. return compare(d);
  262. }
  263. mpfi_t& data() BOOST_NOEXCEPT
  264. {
  265. BOOST_ASSERT(m_data[0].left._mpfr_d);
  266. return m_data;
  267. }
  268. const mpfi_t& data()const BOOST_NOEXCEPT
  269. {
  270. BOOST_ASSERT(m_data[0].left._mpfr_d);
  271. return m_data;
  272. }
  273. mpfr_ptr left_data() BOOST_NOEXCEPT
  274. {
  275. BOOST_ASSERT(m_data[0].left._mpfr_d);
  276. return &(m_data[0].left);
  277. }
  278. mpfr_srcptr left_data()const BOOST_NOEXCEPT
  279. {
  280. BOOST_ASSERT(m_data[0].left._mpfr_d);
  281. return &(m_data[0].left);
  282. }
  283. mpfr_ptr right_data() BOOST_NOEXCEPT
  284. {
  285. BOOST_ASSERT(m_data[0].left._mpfr_d);
  286. return &(m_data[0].right);
  287. }
  288. mpfr_srcptr right_data()const BOOST_NOEXCEPT
  289. {
  290. BOOST_ASSERT(m_data[0].left._mpfr_d);
  291. return &(m_data[0].right);
  292. }
  293. protected:
  294. mpfi_t m_data;
  295. static unsigned& get_default_precision() BOOST_NOEXCEPT
  296. {
  297. static unsigned val = 50;
  298. return val;
  299. }
  300. };
  301. } // namespace detail
  302. template <unsigned digits10>
  303. struct mpfi_float_backend : public detail::mpfi_float_imp<digits10>
  304. {
  305. mpfi_float_backend() : detail::mpfi_float_imp<digits10>() {}
  306. mpfi_float_backend(const mpfi_float_backend& o) : detail::mpfi_float_imp<digits10>(o) {}
  307. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  308. mpfi_float_backend(mpfi_float_backend&& o) : detail::mpfi_float_imp<digits10>(static_cast<detail::mpfi_float_imp<digits10>&&>(o)) {}
  309. #endif
  310. template <unsigned D>
  311. mpfi_float_backend(const mpfi_float_backend<D>& val, typename enable_if_c<D <= digits10>::type* = 0)
  312. : detail::mpfi_float_imp<digits10>()
  313. {
  314. mpfi_set(this->m_data, val.data());
  315. }
  316. template <unsigned D>
  317. explicit mpfi_float_backend(const mpfi_float_backend<D>& val, typename disable_if_c<D <= digits10>::type* = 0)
  318. : detail::mpfi_float_imp<digits10>()
  319. {
  320. mpfi_set(this->m_data, val.data());
  321. }
  322. mpfi_float_backend(const mpfi_t val)
  323. : detail::mpfi_float_imp<digits10>()
  324. {
  325. mpfi_set(this->m_data, val);
  326. }
  327. mpfi_float_backend& operator=(const mpfi_float_backend& o)
  328. {
  329. *static_cast<detail::mpfi_float_imp<digits10>*>(this) = static_cast<detail::mpfi_float_imp<digits10> const&>(o);
  330. return *this;
  331. }
  332. template <unsigned D>
  333. mpfi_float_backend(const mpfr_float_backend<D>& val, typename enable_if_c<D <= digits10>::type* = 0)
  334. : detail::mpfi_float_imp<digits10>()
  335. {
  336. mpfi_set_fr(this->m_data, val.data());
  337. }
  338. template <unsigned D>
  339. mpfi_float_backend& operator=(const mpfr_float_backend<D>& val)
  340. {
  341. mpfi_set_fr(this->m_data, val.data());
  342. return *this;
  343. }
  344. template <unsigned D>
  345. explicit mpfi_float_backend(const mpfr_float_backend<D>& val, typename disable_if_c<D <= digits10>::type* = 0)
  346. : detail::mpfi_float_imp<digits10>()
  347. {
  348. mpfi_set_fr(this->m_data, val.data());
  349. }
  350. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  351. mpfi_float_backend& operator=(mpfi_float_backend&& o) BOOST_NOEXCEPT
  352. {
  353. *static_cast<detail::mpfi_float_imp<digits10>*>(this) = static_cast<detail::mpfi_float_imp<digits10>&&>(o);
  354. return *this;
  355. }
  356. #endif
  357. template <class V>
  358. mpfi_float_backend& operator=(const V& v)
  359. {
  360. *static_cast<detail::mpfi_float_imp<digits10>*>(this) = v;
  361. return *this;
  362. }
  363. mpfi_float_backend& operator=(const mpfi_t val)
  364. {
  365. mpfi_set(this->m_data, val);
  366. return *this;
  367. }
  368. // We don't change our precision here, this is a fixed precision type:
  369. template <unsigned D>
  370. mpfi_float_backend& operator=(const mpfi_float_backend<D>& val)
  371. {
  372. mpfi_set(this->m_data, val.data());
  373. return *this;
  374. }
  375. };
  376. template <>
  377. struct mpfi_float_backend<0> : public detail::mpfi_float_imp<0>
  378. {
  379. mpfi_float_backend() : detail::mpfi_float_imp<0>() {}
  380. mpfi_float_backend(const mpfi_t val)
  381. : detail::mpfi_float_imp<0>(mpfi_get_prec(val))
  382. {
  383. mpfi_set(this->m_data, val);
  384. }
  385. mpfi_float_backend(const mpfi_float_backend& o) : detail::mpfi_float_imp<0>(o) {}
  386. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  387. mpfi_float_backend(mpfi_float_backend&& o) BOOST_NOEXCEPT : detail::mpfi_float_imp<0>(static_cast<detail::mpfi_float_imp<0>&&>(o)) {}
  388. #endif
  389. mpfi_float_backend(const mpfi_float_backend& o, unsigned digits10)
  390. : detail::mpfi_float_imp<0>(digits10)
  391. {
  392. *this = o;
  393. }
  394. template <unsigned D>
  395. mpfi_float_backend(const mpfi_float_backend<D>& val)
  396. : detail::mpfi_float_imp<0>(mpfi_get_prec(val.data()))
  397. {
  398. mpfi_set(this->m_data, val.data());
  399. }
  400. mpfi_float_backend& operator=(const mpfi_float_backend& o)
  401. {
  402. mpfi_set_prec(this->m_data, mpfi_get_prec(o.data()));
  403. mpfi_set(this->m_data, o.data());
  404. return *this;
  405. }
  406. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  407. mpfi_float_backend& operator=(mpfi_float_backend&& o) BOOST_NOEXCEPT
  408. {
  409. *static_cast<detail::mpfi_float_imp<0>*>(this) = static_cast<detail::mpfi_float_imp<0> &&>(o);
  410. return *this;
  411. }
  412. #endif
  413. template <class V>
  414. mpfi_float_backend& operator=(const V& v)
  415. {
  416. *static_cast<detail::mpfi_float_imp<0>*>(this) = v;
  417. return *this;
  418. }
  419. mpfi_float_backend& operator=(const mpfi_t val)
  420. {
  421. mpfi_set_prec(this->m_data, mpfi_get_prec(val));
  422. mpfi_set(this->m_data, val);
  423. return *this;
  424. }
  425. template <unsigned D>
  426. mpfi_float_backend& operator=(const mpfi_float_backend<D>& val)
  427. {
  428. mpfi_set_prec(this->m_data, mpfi_get_prec(val.data()));
  429. mpfi_set(this->m_data, val.data());
  430. return *this;
  431. }
  432. static unsigned default_precision() BOOST_NOEXCEPT
  433. {
  434. return get_default_precision();
  435. }
  436. static void default_precision(unsigned v) BOOST_NOEXCEPT
  437. {
  438. get_default_precision() = v;
  439. }
  440. unsigned precision()const BOOST_NOEXCEPT
  441. {
  442. return multiprecision::detail::digits2_2_10(mpfi_get_prec(this->m_data));
  443. }
  444. void precision(unsigned digits10) BOOST_NOEXCEPT
  445. {
  446. mpfi_set_prec(this->m_data, multiprecision::detail::digits2_2_10((digits10)));
  447. }
  448. };
  449. template <unsigned digits10, class T>
  450. inline typename enable_if<is_arithmetic<T>, bool>::type eval_eq(const mpfi_float_backend<digits10>& a, const T& b) BOOST_NOEXCEPT
  451. {
  452. return a.compare(b) == 0;
  453. }
  454. template <unsigned digits10, class T>
  455. inline typename enable_if<is_arithmetic<T>, bool>::type eval_lt(const mpfi_float_backend<digits10>& a, const T& b) BOOST_NOEXCEPT
  456. {
  457. return a.compare(b) < 0;
  458. }
  459. template <unsigned digits10, class T>
  460. inline typename enable_if<is_arithmetic<T>, bool>::type eval_gt(const mpfi_float_backend<digits10>& a, const T& b) BOOST_NOEXCEPT
  461. {
  462. return a.compare(b) > 0;
  463. }
  464. template <unsigned D1, unsigned D2>
  465. inline void eval_add(mpfi_float_backend<D1>& result, const mpfi_float_backend<D2>& o)
  466. {
  467. mpfi_add(result.data(), result.data(), o.data());
  468. }
  469. template <unsigned D1, unsigned D2>
  470. inline void eval_subtract(mpfi_float_backend<D1>& result, const mpfi_float_backend<D2>& o)
  471. {
  472. mpfi_sub(result.data(), result.data(), o.data());
  473. }
  474. template <unsigned D1, unsigned D2>
  475. inline void eval_multiply(mpfi_float_backend<D1>& result, const mpfi_float_backend<D2>& o)
  476. {
  477. if((void*)&result == (void*)&o)
  478. mpfi_sqr(result.data(), o.data());
  479. else
  480. mpfi_mul(result.data(), result.data(), o.data());
  481. }
  482. template <unsigned D1, unsigned D2>
  483. inline void eval_divide(mpfi_float_backend<D1>& result, const mpfi_float_backend<D2>& o)
  484. {
  485. mpfi_div(result.data(), result.data(), o.data());
  486. }
  487. template <unsigned digits10>
  488. inline void eval_add(mpfi_float_backend<digits10>& result, unsigned long i)
  489. {
  490. mpfi_add_ui(result.data(), result.data(), i);
  491. }
  492. template <unsigned digits10>
  493. inline void eval_subtract(mpfi_float_backend<digits10>& result, unsigned long i)
  494. {
  495. mpfi_sub_ui(result.data(), result.data(), i);
  496. }
  497. template <unsigned digits10>
  498. inline void eval_multiply(mpfi_float_backend<digits10>& result, unsigned long i)
  499. {
  500. mpfi_mul_ui(result.data(), result.data(), i);
  501. }
  502. template <unsigned digits10>
  503. inline void eval_divide(mpfi_float_backend<digits10>& result, unsigned long i)
  504. {
  505. mpfi_div_ui(result.data(), result.data(), i);
  506. }
  507. template <unsigned digits10>
  508. inline void eval_add(mpfi_float_backend<digits10>& result, long i)
  509. {
  510. if(i > 0)
  511. mpfi_add_ui(result.data(), result.data(), i);
  512. else
  513. mpfi_sub_ui(result.data(), result.data(), boost::multiprecision::detail::unsigned_abs(i));
  514. }
  515. template <unsigned digits10>
  516. inline void eval_subtract(mpfi_float_backend<digits10>& result, long i)
  517. {
  518. if(i > 0)
  519. mpfi_sub_ui(result.data(), result.data(), i);
  520. else
  521. mpfi_add_ui(result.data(), result.data(), boost::multiprecision::detail::unsigned_abs(i));
  522. }
  523. template <unsigned digits10>
  524. inline void eval_multiply(mpfi_float_backend<digits10>& result, long i)
  525. {
  526. mpfi_mul_ui(result.data(), result.data(), boost::multiprecision::detail::unsigned_abs(i));
  527. if(i < 0)
  528. mpfi_neg(result.data(), result.data());
  529. }
  530. template <unsigned digits10>
  531. inline void eval_divide(mpfi_float_backend<digits10>& result, long i)
  532. {
  533. mpfi_div_ui(result.data(), result.data(), boost::multiprecision::detail::unsigned_abs(i));
  534. if(i < 0)
  535. mpfi_neg(result.data(), result.data());
  536. }
  537. //
  538. // Specialised 3 arg versions of the basic operators:
  539. //
  540. template <unsigned D1, unsigned D2, unsigned D3>
  541. inline void eval_add(mpfi_float_backend<D1>& a, const mpfi_float_backend<D2>& x, const mpfi_float_backend<D3>& y)
  542. {
  543. mpfi_add(a.data(), x.data(), y.data());
  544. }
  545. template <unsigned D1, unsigned D2>
  546. inline void eval_add(mpfi_float_backend<D1>& a, const mpfi_float_backend<D2>& x, unsigned long y)
  547. {
  548. mpfi_add_ui(a.data(), x.data(), y);
  549. }
  550. template <unsigned D1, unsigned D2>
  551. inline void eval_add(mpfi_float_backend<D1>& a, const mpfi_float_backend<D2>& x, long y)
  552. {
  553. if(y < 0)
  554. mpfi_sub_ui(a.data(), x.data(), boost::multiprecision::detail::unsigned_abs(y));
  555. else
  556. mpfi_add_ui(a.data(), x.data(), y);
  557. }
  558. template <unsigned D1, unsigned D2>
  559. inline void eval_add(mpfi_float_backend<D1>& a, unsigned long x, const mpfi_float_backend<D2>& y)
  560. {
  561. mpfi_add_ui(a.data(), y.data(), x);
  562. }
  563. template <unsigned D1, unsigned D2>
  564. inline void eval_add(mpfi_float_backend<D1>& a, long x, const mpfi_float_backend<D2>& y)
  565. {
  566. if(x < 0)
  567. {
  568. mpfi_ui_sub(a.data(), boost::multiprecision::detail::unsigned_abs(x), y.data());
  569. mpfi_neg(a.data(), a.data());
  570. }
  571. else
  572. mpfi_add_ui(a.data(), y.data(), x);
  573. }
  574. template <unsigned D1, unsigned D2, unsigned D3>
  575. inline void eval_subtract(mpfi_float_backend<D1>& a, const mpfi_float_backend<D2>& x, const mpfi_float_backend<D3>& y)
  576. {
  577. mpfi_sub(a.data(), x.data(), y.data());
  578. }
  579. template <unsigned D1, unsigned D2>
  580. inline void eval_subtract(mpfi_float_backend<D1>& a, const mpfi_float_backend<D2>& x, unsigned long y)
  581. {
  582. mpfi_sub_ui(a.data(), x.data(), y);
  583. }
  584. template <unsigned D1, unsigned D2>
  585. inline void eval_subtract(mpfi_float_backend<D1>& a, const mpfi_float_backend<D2>& x, long y)
  586. {
  587. if(y < 0)
  588. mpfi_add_ui(a.data(), x.data(), boost::multiprecision::detail::unsigned_abs(y));
  589. else
  590. mpfi_sub_ui(a.data(), x.data(), y);
  591. }
  592. template <unsigned D1, unsigned D2>
  593. inline void eval_subtract(mpfi_float_backend<D1>& a, unsigned long x, const mpfi_float_backend<D2>& y)
  594. {
  595. mpfi_ui_sub(a.data(), x, y.data());
  596. }
  597. template <unsigned D1, unsigned D2>
  598. inline void eval_subtract(mpfi_float_backend<D1>& a, long x, const mpfi_float_backend<D2>& y)
  599. {
  600. if(x < 0)
  601. {
  602. mpfi_add_ui(a.data(), y.data(), boost::multiprecision::detail::unsigned_abs(x));
  603. mpfi_neg(a.data(), a.data());
  604. }
  605. else
  606. mpfi_ui_sub(a.data(), x, y.data());
  607. }
  608. template <unsigned D1, unsigned D2, unsigned D3>
  609. inline void eval_multiply(mpfi_float_backend<D1>& a, const mpfi_float_backend<D2>& x, const mpfi_float_backend<D3>& y)
  610. {
  611. if((void*)&x == (void*)&y)
  612. mpfi_sqr(a.data(), x.data());
  613. else
  614. mpfi_mul(a.data(), x.data(), y.data());
  615. }
  616. template <unsigned D1, unsigned D2>
  617. inline void eval_multiply(mpfi_float_backend<D1>& a, const mpfi_float_backend<D2>& x, unsigned long y)
  618. {
  619. mpfi_mul_ui(a.data(), x.data(), y);
  620. }
  621. template <unsigned D1, unsigned D2>
  622. inline void eval_multiply(mpfi_float_backend<D1>& a, const mpfi_float_backend<D2>& x, long y)
  623. {
  624. if(y < 0)
  625. {
  626. mpfi_mul_ui(a.data(), x.data(), boost::multiprecision::detail::unsigned_abs(y));
  627. a.negate();
  628. }
  629. else
  630. mpfi_mul_ui(a.data(), x.data(), y);
  631. }
  632. template <unsigned D1, unsigned D2>
  633. inline void eval_multiply(mpfi_float_backend<D1>& a, unsigned long x, const mpfi_float_backend<D2>& y)
  634. {
  635. mpfi_mul_ui(a.data(), y.data(), x);
  636. }
  637. template <unsigned D1, unsigned D2>
  638. inline void eval_multiply(mpfi_float_backend<D1>& a, long x, const mpfi_float_backend<D2>& y)
  639. {
  640. if(x < 0)
  641. {
  642. mpfi_mul_ui(a.data(), y.data(), boost::multiprecision::detail::unsigned_abs(x));
  643. mpfi_neg(a.data(), a.data());
  644. }
  645. else
  646. mpfi_mul_ui(a.data(), y.data(), x);
  647. }
  648. template <unsigned D1, unsigned D2, unsigned D3>
  649. inline void eval_divide(mpfi_float_backend<D1>& a, const mpfi_float_backend<D2>& x, const mpfi_float_backend<D3>& y)
  650. {
  651. mpfi_div(a.data(), x.data(), y.data());
  652. }
  653. template <unsigned D1, unsigned D2>
  654. inline void eval_divide(mpfi_float_backend<D1>& a, const mpfi_float_backend<D2>& x, unsigned long y)
  655. {
  656. mpfi_div_ui(a.data(), x.data(), y);
  657. }
  658. template <unsigned D1, unsigned D2>
  659. inline void eval_divide(mpfi_float_backend<D1>& a, const mpfi_float_backend<D2>& x, long y)
  660. {
  661. if(y < 0)
  662. {
  663. mpfi_div_ui(a.data(), x.data(), boost::multiprecision::detail::unsigned_abs(y));
  664. a.negate();
  665. }
  666. else
  667. mpfi_div_ui(a.data(), x.data(), y);
  668. }
  669. template <unsigned D1, unsigned D2>
  670. inline void eval_divide(mpfi_float_backend<D1>& a, unsigned long x, const mpfi_float_backend<D2>& y)
  671. {
  672. mpfi_ui_div(a.data(), x, y.data());
  673. }
  674. template <unsigned D1, unsigned D2>
  675. inline void eval_divide(mpfi_float_backend<D1>& a, long x, const mpfi_float_backend<D2>& y)
  676. {
  677. if(x < 0)
  678. {
  679. mpfi_ui_div(a.data(), boost::multiprecision::detail::unsigned_abs(x), y.data());
  680. mpfi_neg(a.data(), a.data());
  681. }
  682. else
  683. mpfi_ui_div(a.data(), x, y.data());
  684. }
  685. template <unsigned digits10>
  686. inline bool eval_is_zero(const mpfi_float_backend<digits10>& val) BOOST_NOEXCEPT
  687. {
  688. return 0 != mpfi_is_zero(val.data());
  689. }
  690. template <unsigned digits10>
  691. inline int eval_get_sign(const mpfi_float_backend<digits10>& val)
  692. {
  693. return detail::mpfi_sgn(val.data());
  694. }
  695. template <unsigned digits10>
  696. inline void eval_convert_to(unsigned long* result, const mpfi_float_backend<digits10>& val)
  697. {
  698. mpfr_float_backend<digits10> t;
  699. mpfi_mid(t.data(), val.data());
  700. eval_convert_to(result, t);
  701. }
  702. template <unsigned digits10>
  703. inline void eval_convert_to(long* result, const mpfi_float_backend<digits10>& val)
  704. {
  705. mpfr_float_backend<digits10> t;
  706. mpfi_mid(t.data(), val.data());
  707. eval_convert_to(result, t);
  708. }
  709. #ifdef _MPFR_H_HAVE_INTMAX_T
  710. template <unsigned digits10>
  711. inline void eval_convert_to(boost::ulong_long_type* result, const mpfi_float_backend<digits10>& val)
  712. {
  713. mpfr_float_backend<digits10> t;
  714. mpfi_mid(t.data(), val.data());
  715. eval_convert_to(result, t);
  716. }
  717. template <unsigned digits10>
  718. inline void eval_convert_to(boost::long_long_type* result, const mpfi_float_backend<digits10>& val)
  719. {
  720. mpfr_float_backend<digits10> t;
  721. mpfi_mid(t.data(), val.data());
  722. eval_convert_to(result, t);
  723. }
  724. #endif
  725. template <unsigned digits10>
  726. inline void eval_convert_to(double* result, const mpfi_float_backend<digits10>& val) BOOST_NOEXCEPT
  727. {
  728. *result = mpfi_get_d(val.data());
  729. }
  730. template <unsigned digits10>
  731. inline void eval_convert_to(long double* result, const mpfi_float_backend<digits10>& val) BOOST_NOEXCEPT
  732. {
  733. mpfr_float_backend<digits10> t;
  734. mpfi_mid(t.data(), val.data());
  735. eval_convert_to(result, t);
  736. }
  737. template <unsigned D1, unsigned D2, mpfr_allocation_type AllocationType>
  738. inline void assign_components(mpfi_float_backend<D1>& result, const mpfr_float_backend<D2, AllocationType>& a, const mpfr_float_backend<D2, AllocationType>& b)
  739. {
  740. using default_ops::eval_fpclassify;
  741. if(eval_fpclassify(a) == (int)FP_NAN)
  742. {
  743. mpfi_set_fr(result.data(), a.data());
  744. }
  745. else if(eval_fpclassify(b) == (int)FP_NAN)
  746. {
  747. mpfi_set_fr(result.data(), b.data());
  748. }
  749. else
  750. {
  751. if(a.compare(b) > 0)
  752. {
  753. BOOST_THROW_EXCEPTION(std::runtime_error("Attempt to create interval with invalid range (start is greater than end)."));
  754. }
  755. mpfi_interv_fr(result.data(), a.data(), b.data());
  756. }
  757. }
  758. template <unsigned Digits10, class V>
  759. inline typename enable_if_c<is_convertible<V, number<mpfr_float_backend<Digits10, allocate_dynamic>, et_on> >::value >::type
  760. assign_components(mpfi_float_backend<Digits10>& result, const V& a, const V& b)
  761. {
  762. number<mpfr_float_backend<Digits10, allocate_dynamic>, et_on> x(a), y(b);
  763. assign_components(result, x.backend(), y.backend());
  764. }
  765. //
  766. // Native non-member operations:
  767. //
  768. template <unsigned Digits10>
  769. inline void eval_sqrt(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& val)
  770. {
  771. mpfi_sqrt(result.data(), val.data());
  772. }
  773. template <unsigned Digits10>
  774. inline void eval_abs(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& val)
  775. {
  776. mpfi_abs(result.data(), val.data());
  777. }
  778. template <unsigned Digits10>
  779. inline void eval_fabs(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& val)
  780. {
  781. mpfi_abs(result.data(), val.data());
  782. }
  783. template <unsigned Digits10>
  784. inline void eval_ceil(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& val)
  785. {
  786. mpfr_float_backend<Digits10> a, b;
  787. mpfr_set(a.data(), val.left_data(), GMP_RNDN);
  788. mpfr_set(b.data(), val.right_data(), GMP_RNDN);
  789. eval_ceil(a, a);
  790. eval_ceil(b, b);
  791. if(a.compare(b) != 0)
  792. {
  793. BOOST_THROW_EXCEPTION(interval_error("Attempt to take the ceil of a value that straddles an integer boundary."));
  794. }
  795. mpfi_set_fr(result.data(), a.data());
  796. }
  797. template <unsigned Digits10>
  798. inline void eval_floor(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& val)
  799. {
  800. mpfr_float_backend<Digits10> a, b;
  801. mpfr_set(a.data(), val.left_data(), GMP_RNDN);
  802. mpfr_set(b.data(), val.right_data(), GMP_RNDN);
  803. eval_floor(a, a);
  804. eval_floor(b, b);
  805. if(a.compare(b) != 0)
  806. {
  807. BOOST_THROW_EXCEPTION(interval_error("Attempt to take the floor of a value that straddles an integer boundary."));
  808. }
  809. mpfi_set_fr(result.data(), a.data());
  810. }
  811. template <unsigned Digits10>
  812. inline void eval_ldexp(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& val, long e)
  813. {
  814. if(e > 0)
  815. mpfi_mul_2exp(result.data(), val.data(), e);
  816. else if(e < 0)
  817. mpfi_div_2exp(result.data(), val.data(), -e);
  818. else
  819. result = val;
  820. }
  821. template <unsigned Digits10>
  822. inline void eval_frexp(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& val, int* e)
  823. {
  824. mpfr_float_backend<Digits10> t, rt;
  825. mpfi_mid(t.data(), val.data());
  826. eval_frexp(rt, t, e);
  827. eval_ldexp(result, val, -*e);
  828. }
  829. template <unsigned Digits10>
  830. inline void eval_frexp(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& val, long* e)
  831. {
  832. mpfr_float_backend<Digits10> t, rt;
  833. mpfi_mid(t.data(), val.data());
  834. eval_frexp(rt, t, e);
  835. eval_ldexp(result, val, -*e);
  836. }
  837. template <unsigned Digits10>
  838. inline int eval_fpclassify(const mpfi_float_backend<Digits10>& val) BOOST_NOEXCEPT
  839. {
  840. return mpfi_inf_p(val.data()) ? FP_INFINITE : mpfi_nan_p(val.data()) ? FP_NAN : mpfi_is_zero(val.data()) ? FP_ZERO : FP_NORMAL;
  841. }
  842. template <unsigned Digits10>
  843. inline void eval_pow(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& b, const mpfi_float_backend<Digits10>& e)
  844. {
  845. typedef typename boost::multiprecision::detail::canonical<unsigned, mpfi_float_backend<Digits10> >::type ui_type;
  846. using default_ops::eval_get_sign;
  847. int s = eval_get_sign(b);
  848. if(s == 0)
  849. {
  850. if(eval_get_sign(e) == 0)
  851. {
  852. result = ui_type(1);
  853. }
  854. else
  855. {
  856. result = ui_type(0);
  857. }
  858. return;
  859. }
  860. if(s < 0)
  861. {
  862. if(eval_get_sign(e) < 0)
  863. {
  864. mpfi_float_backend<Digits10> t1, t2;
  865. t1 = e;
  866. t1.negate();
  867. eval_pow(t2, b, t1);
  868. t1 = ui_type(1);
  869. eval_divide(result, t1, t2);
  870. return;
  871. }
  872. typename boost::multiprecision::detail::canonical<boost::uintmax_t, mpfi_float_backend<Digits10> >::type an;
  873. #ifndef BOOST_NO_EXCEPTIONS
  874. try
  875. {
  876. #endif
  877. using default_ops::eval_convert_to;
  878. eval_convert_to(&an, e);
  879. if(e.compare(an) == 0)
  880. {
  881. mpfi_float_backend<Digits10> pb(b);
  882. pb.negate();
  883. eval_pow(result, pb, e);
  884. if(an & 1u)
  885. result.negate();
  886. return;
  887. }
  888. #ifndef BOOST_NO_EXCEPTIONS
  889. }
  890. catch(const std::exception&)
  891. {
  892. // conversion failed, just fall through, value is not an integer.
  893. }
  894. #endif
  895. result = std::numeric_limits<number<mpfi_float_backend<Digits10>, et_on> >::quiet_NaN().backend();
  896. return;
  897. }
  898. mpfi_log(result.data(), b.data());
  899. mpfi_mul(result.data(), result.data(), e.data());
  900. mpfi_exp(result.data(), result.data());
  901. }
  902. template <unsigned Digits10>
  903. inline void eval_exp(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& arg)
  904. {
  905. mpfi_exp(result.data(), arg.data());
  906. }
  907. template <unsigned Digits10>
  908. inline void eval_log(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& arg)
  909. {
  910. mpfi_log(result.data(), arg.data());
  911. }
  912. template <unsigned Digits10>
  913. inline void eval_log10(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& arg)
  914. {
  915. mpfi_log10(result.data(), arg.data());
  916. }
  917. template <unsigned Digits10>
  918. inline void eval_sin(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& arg)
  919. {
  920. mpfi_sin(result.data(), arg.data());
  921. }
  922. template <unsigned Digits10>
  923. inline void eval_cos(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& arg)
  924. {
  925. mpfi_cos(result.data(), arg.data());
  926. }
  927. template <unsigned Digits10>
  928. inline void eval_tan(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& arg)
  929. {
  930. mpfi_tan(result.data(), arg.data());
  931. }
  932. template <unsigned Digits10>
  933. inline void eval_asin(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& arg)
  934. {
  935. mpfi_asin(result.data(), arg.data());
  936. }
  937. template <unsigned Digits10>
  938. inline void eval_acos(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& arg)
  939. {
  940. mpfi_acos(result.data(), arg.data());
  941. }
  942. template <unsigned Digits10>
  943. inline void eval_atan(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& arg)
  944. {
  945. mpfi_atan(result.data(), arg.data());
  946. }
  947. template <unsigned Digits10>
  948. inline void eval_atan2(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& arg1, const mpfi_float_backend<Digits10>& arg2)
  949. {
  950. mpfi_atan2(result.data(), arg1.data(), arg2.data());
  951. }
  952. template <unsigned Digits10>
  953. inline void eval_sinh(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& arg)
  954. {
  955. mpfi_sinh(result.data(), arg.data());
  956. }
  957. template <unsigned Digits10>
  958. inline void eval_cosh(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& arg)
  959. {
  960. mpfi_cosh(result.data(), arg.data());
  961. }
  962. template <unsigned Digits10>
  963. inline void eval_tanh(mpfi_float_backend<Digits10>& result, const mpfi_float_backend<Digits10>& arg)
  964. {
  965. mpfi_tanh(result.data(), arg.data());
  966. }
  967. } // namespace backends
  968. #ifdef BOOST_NO_SFINAE_EXPR
  969. namespace detail{
  970. template<unsigned D1, unsigned D2>
  971. struct is_explicitly_convertible<backends::mpfi_float_backend<D1>, backends::mpfi_float_backend<D2> > : public mpl::true_ {};
  972. }
  973. #endif
  974. template<>
  975. struct number_category<detail::canonical<mpfi_t, backends::mpfi_float_backend<0> >::type> : public mpl::int_<number_kind_floating_point>{};
  976. template <unsigned Digits10>
  977. struct is_interval_number<backends::mpfi_float_backend<Digits10> > : public mpl::true_ {};
  978. using boost::multiprecision::backends::mpfi_float_backend;
  979. typedef number<mpfi_float_backend<50> > mpfi_float_50;
  980. typedef number<mpfi_float_backend<100> > mpfi_float_100;
  981. typedef number<mpfi_float_backend<500> > mpfi_float_500;
  982. typedef number<mpfi_float_backend<1000> > mpfi_float_1000;
  983. typedef number<mpfi_float_backend<0> > mpfi_float;
  984. //
  985. // Special interval specific functions:
  986. //
  987. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  988. inline number<mpfr_float_backend<Digits10>, ExpressionTemplates> lower(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& val)
  989. {
  990. number<mpfr_float_backend<Digits10> > result;
  991. mpfr_set(result.backend().data(), val.backend().left_data(), GMP_RNDN);
  992. return result;
  993. }
  994. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  995. inline number<mpfr_float_backend<Digits10>, ExpressionTemplates> upper(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& val)
  996. {
  997. number<mpfr_float_backend<Digits10> > result;
  998. mpfr_set(result.backend().data(), val.backend().right_data(), GMP_RNDN);
  999. return result;
  1000. }
  1001. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  1002. inline number<mpfr_float_backend<Digits10>, ExpressionTemplates> median(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& val)
  1003. {
  1004. number<mpfr_float_backend<Digits10> > result;
  1005. mpfi_mid(result.backend().data(), val.backend().data());
  1006. return result;
  1007. }
  1008. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  1009. inline number<mpfr_float_backend<Digits10>, ExpressionTemplates> width(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& val)
  1010. {
  1011. number<mpfr_float_backend<Digits10> > result;
  1012. mpfi_diam_abs(result.backend().data(), val.backend().data());
  1013. return result;
  1014. }
  1015. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  1016. inline number<mpfi_float_backend<Digits10>, ExpressionTemplates> intersect(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a, const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& b)
  1017. {
  1018. number<mpfi_float_backend<Digits10>, ExpressionTemplates> result;
  1019. mpfi_intersect(result.backend().data(), a.backend().data(), b.backend().data());
  1020. return result;
  1021. }
  1022. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  1023. inline number<mpfi_float_backend<Digits10>, ExpressionTemplates> hull(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a, const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& b)
  1024. {
  1025. number<mpfi_float_backend<Digits10>, ExpressionTemplates> result;
  1026. mpfi_union(result.backend().data(), a.backend().data(), b.backend().data());
  1027. return result;
  1028. }
  1029. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  1030. inline bool overlap(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a, const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& b)
  1031. {
  1032. return (lower(a) <= lower(b) && lower(b) <= upper(a)) ||
  1033. (lower(b) <= lower(a) && lower(a) <= upper(b));
  1034. }
  1035. template <unsigned Digits10, expression_template_option ExpressionTemplates1, expression_template_option ExpressionTemplates2>
  1036. inline bool in(const number<mpfr_float_backend<Digits10>, ExpressionTemplates1>& a, const number<mpfi_float_backend<Digits10>, ExpressionTemplates2>& b)
  1037. {
  1038. return mpfi_is_inside_fr(a.backend().data(), b.backend().data()) != 0;
  1039. }
  1040. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  1041. inline bool zero_in(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a)
  1042. {
  1043. return mpfi_has_zero(a.backend().data()) != 0;
  1044. }
  1045. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  1046. inline bool subset(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a, const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& b)
  1047. {
  1048. return mpfi_is_inside(a.backend().data(), b.backend().data()) != 0;
  1049. }
  1050. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  1051. inline bool proper_subset(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a, const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& b)
  1052. {
  1053. return mpfi_is_strictly_inside(a.backend().data(), b.backend().data()) != 0;
  1054. }
  1055. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  1056. inline bool empty(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a)
  1057. {
  1058. return mpfi_is_empty(a.backend().data()) != 0;
  1059. }
  1060. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  1061. inline bool singleton(const number<mpfi_float_backend<Digits10>, ExpressionTemplates>& a)
  1062. {
  1063. return mpfr_cmp(a.backend().left_data(), a.backend().right_data()) == 0;
  1064. }
  1065. template <unsigned Digits10, expression_template_option ExpressionTemplates>
  1066. struct component_type<number<mpfi_float_backend<Digits10>, ExpressionTemplates> >
  1067. {
  1068. typedef number<mpfr_float_backend<Digits10>, ExpressionTemplates> type;
  1069. };
  1070. } // namespace multiprecision
  1071. namespace math{
  1072. namespace tools{
  1073. template <>
  1074. inline int digits<boost::multiprecision::mpfi_float>()
  1075. #ifdef BOOST_MATH_NOEXCEPT
  1076. BOOST_NOEXCEPT
  1077. #endif
  1078. {
  1079. return boost::multiprecision::backends::detail::get_default_precision();
  1080. }
  1081. template <>
  1082. inline int digits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, boost::multiprecision::et_off> >()
  1083. #ifdef BOOST_MATH_NOEXCEPT
  1084. BOOST_NOEXCEPT
  1085. #endif
  1086. {
  1087. return boost::multiprecision::backends::detail::get_default_precision();
  1088. }
  1089. } // namespace tools
  1090. namespace constants{ namespace detail{
  1091. template <class T> struct constant_pi;
  1092. template <class T> struct constant_ln_two;
  1093. template <class T> struct constant_euler;
  1094. template <class T> struct constant_catalan;
  1095. //
  1096. // Initializer: ensure all our constants are initialized prior to the first call of main:
  1097. //
  1098. template <class T>
  1099. struct mpfi_initializer
  1100. {
  1101. struct init
  1102. {
  1103. init()
  1104. {
  1105. boost::math::constants::pi<T>();
  1106. boost::math::constants::ln_two<T>();
  1107. boost::math::constants::euler<T>();
  1108. boost::math::constants::catalan<T>();
  1109. }
  1110. void force_instantiate()const{}
  1111. };
  1112. static const init initializer;
  1113. static void force_instantiate()
  1114. {
  1115. initializer.force_instantiate();
  1116. }
  1117. };
  1118. template <class T>
  1119. const typename mpfi_initializer<T>::init mpfi_initializer<T>::initializer;
  1120. template<unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1121. struct constant_pi<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >
  1122. {
  1123. typedef boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> result_type;
  1124. template<int N>
  1125. static inline result_type const& get(const mpl::int_<N>&)
  1126. {
  1127. mpfi_initializer<result_type>::force_instantiate();
  1128. static result_type result;
  1129. static bool has_init = false;
  1130. if(!has_init)
  1131. {
  1132. has_init = true;
  1133. mpfi_const_pi(result.backend().data());
  1134. }
  1135. return result;
  1136. }
  1137. };
  1138. template<unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1139. struct constant_ln_two<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >
  1140. {
  1141. typedef boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> result_type;
  1142. template<int N>
  1143. static inline result_type const& get(const mpl::int_<N>&)
  1144. {
  1145. mpfi_initializer<result_type>::force_instantiate();
  1146. static result_type result;
  1147. static bool has_init = false;
  1148. if(!has_init)
  1149. {
  1150. has_init = true;
  1151. mpfi_const_log2(result.backend().data());
  1152. }
  1153. return result;
  1154. }
  1155. };
  1156. template<unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1157. struct constant_euler<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >
  1158. {
  1159. typedef boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> result_type;
  1160. template<int N>
  1161. static inline result_type const& get(const mpl::int_<N>&)
  1162. {
  1163. mpfi_initializer<result_type>::force_instantiate();
  1164. static result_type result;
  1165. static bool has_init = false;
  1166. if(!has_init)
  1167. {
  1168. has_init = true;
  1169. mpfi_const_euler(result.backend().data());
  1170. }
  1171. return result;
  1172. }
  1173. };
  1174. template<unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1175. struct constant_catalan<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >
  1176. {
  1177. typedef boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> result_type;
  1178. template<int N>
  1179. static inline result_type const& get(const mpl::int_<N>&)
  1180. {
  1181. mpfi_initializer<result_type>::force_instantiate();
  1182. static result_type result;
  1183. static bool has_init = false;
  1184. if(!has_init)
  1185. {
  1186. has_init = true;
  1187. mpfi_const_catalan(result.backend().data());
  1188. }
  1189. return result;
  1190. }
  1191. };
  1192. }} // namespaces
  1193. }} // namespaces
  1194. namespace std{
  1195. //
  1196. // numeric_limits [partial] specializations for the types declared in this header:
  1197. //
  1198. template<unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1199. class numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >
  1200. {
  1201. typedef boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> number_type;
  1202. public:
  1203. BOOST_STATIC_CONSTEXPR bool is_specialized = true;
  1204. static number_type (min)()
  1205. {
  1206. initializer.do_nothing();
  1207. static std::pair<bool, number_type> value;
  1208. if(!value.first)
  1209. {
  1210. value.first = true;
  1211. value.second = 0.5;
  1212. mpfi_div_2exp(value.second.backend().data(), value.second.backend().data(), -mpfr_get_emin());
  1213. }
  1214. return value.second;
  1215. }
  1216. static number_type (max)()
  1217. {
  1218. initializer.do_nothing();
  1219. static std::pair<bool, number_type> value;
  1220. if(!value.first)
  1221. {
  1222. value.first = true;
  1223. value.second = 0.5;
  1224. mpfi_mul_2exp(value.second.backend().data(), value.second.backend().data(), mpfr_get_emax());
  1225. }
  1226. return value.second;
  1227. }
  1228. BOOST_STATIC_CONSTEXPR number_type lowest()
  1229. {
  1230. return -(max)();
  1231. }
  1232. BOOST_STATIC_CONSTEXPR int digits = static_cast<int>((Digits10 * 1000L) / 301L + ((Digits10 * 1000L) % 301 ? 2 : 1));
  1233. BOOST_STATIC_CONSTEXPR int digits10 = Digits10;
  1234. // Is this really correct???
  1235. BOOST_STATIC_CONSTEXPR int max_digits10 = Digits10 + 3;
  1236. BOOST_STATIC_CONSTEXPR bool is_signed = true;
  1237. BOOST_STATIC_CONSTEXPR bool is_integer = false;
  1238. BOOST_STATIC_CONSTEXPR bool is_exact = false;
  1239. BOOST_STATIC_CONSTEXPR int radix = 2;
  1240. static number_type epsilon()
  1241. {
  1242. initializer.do_nothing();
  1243. static std::pair<bool, number_type> value;
  1244. if(!value.first)
  1245. {
  1246. value.first = true;
  1247. value.second = 1;
  1248. mpfi_div_2exp(value.second.backend().data(), value.second.backend().data(), std::numeric_limits<number_type>::digits - 1);
  1249. }
  1250. return value.second;
  1251. }
  1252. // What value should this be????
  1253. static number_type round_error()
  1254. {
  1255. // returns epsilon/2
  1256. initializer.do_nothing();
  1257. static std::pair<bool, number_type> value;
  1258. if(!value.first)
  1259. {
  1260. value.first = true;
  1261. value.second = 1;
  1262. mpfi_div_2exp(value.second.backend().data(), value.second.backend().data(), 1);
  1263. }
  1264. return value.second;
  1265. }
  1266. BOOST_STATIC_CONSTEXPR long min_exponent = MPFR_EMIN_DEFAULT;
  1267. BOOST_STATIC_CONSTEXPR long min_exponent10 = (MPFR_EMIN_DEFAULT / 1000) * 301L;
  1268. BOOST_STATIC_CONSTEXPR long max_exponent = MPFR_EMAX_DEFAULT;
  1269. BOOST_STATIC_CONSTEXPR long max_exponent10 = (MPFR_EMAX_DEFAULT / 1000) * 301L;
  1270. BOOST_STATIC_CONSTEXPR bool has_infinity = true;
  1271. BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = true;
  1272. BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false;
  1273. BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent;
  1274. BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false;
  1275. static number_type infinity()
  1276. {
  1277. initializer.do_nothing();
  1278. static std::pair<bool, number_type> value;
  1279. if(!value.first)
  1280. {
  1281. boost::multiprecision::mpfr_float_backend<Digits10> t;
  1282. mpfr_set_inf(t.data(), 1);
  1283. value.first = true;
  1284. mpfi_set_fr(value.second.backend().data(), t.data());
  1285. }
  1286. return value.second;
  1287. }
  1288. static number_type quiet_NaN()
  1289. {
  1290. initializer.do_nothing();
  1291. static std::pair<bool, number_type> value;
  1292. if(!value.first)
  1293. {
  1294. boost::multiprecision::mpfr_float_backend<Digits10> t;
  1295. mpfr_set_nan(t.data());
  1296. value.first = true;
  1297. mpfi_set_fr(value.second.backend().data(), t.data());
  1298. }
  1299. return value.second;
  1300. }
  1301. BOOST_STATIC_CONSTEXPR number_type signaling_NaN()
  1302. {
  1303. return number_type(0);
  1304. }
  1305. BOOST_STATIC_CONSTEXPR number_type denorm_min() { return number_type(0); }
  1306. BOOST_STATIC_CONSTEXPR bool is_iec559 = false;
  1307. BOOST_STATIC_CONSTEXPR bool is_bounded = true;
  1308. BOOST_STATIC_CONSTEXPR bool is_modulo = false;
  1309. BOOST_STATIC_CONSTEXPR bool traps = true;
  1310. BOOST_STATIC_CONSTEXPR bool tinyness_before = false;
  1311. BOOST_STATIC_CONSTEXPR float_round_style round_style = round_to_nearest;
  1312. private:
  1313. struct data_initializer
  1314. {
  1315. data_initializer()
  1316. {
  1317. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<digits10> > >::epsilon();
  1318. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<digits10> > >::round_error();
  1319. (std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<digits10> > >::min)();
  1320. (std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<digits10> > >::max)();
  1321. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<digits10> > >::infinity();
  1322. std::numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<digits10> > >::quiet_NaN();
  1323. }
  1324. void do_nothing()const{}
  1325. };
  1326. static const data_initializer initializer;
  1327. };
  1328. template<unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1329. const typename numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::data_initializer numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::initializer;
  1330. #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
  1331. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1332. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::digits;
  1333. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1334. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::digits10;
  1335. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1336. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::max_digits10;
  1337. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1338. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::is_signed;
  1339. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1340. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::is_integer;
  1341. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1342. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::is_exact;
  1343. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1344. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::radix;
  1345. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1346. BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::min_exponent;
  1347. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1348. BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::min_exponent10;
  1349. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1350. BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::max_exponent;
  1351. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1352. BOOST_CONSTEXPR_OR_CONST long numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::max_exponent10;
  1353. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1354. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::has_infinity;
  1355. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1356. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::has_quiet_NaN;
  1357. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1358. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::has_signaling_NaN;
  1359. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1360. BOOST_CONSTEXPR_OR_CONST float_denorm_style numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::has_denorm;
  1361. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1362. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::has_denorm_loss;
  1363. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1364. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::is_iec559;
  1365. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1366. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::is_bounded;
  1367. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1368. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::is_modulo;
  1369. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1370. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::traps;
  1371. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1372. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::tinyness_before;
  1373. template <unsigned Digits10, boost::multiprecision::expression_template_option ExpressionTemplates>
  1374. BOOST_CONSTEXPR_OR_CONST float_round_style numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<Digits10>, ExpressionTemplates> >::round_style;
  1375. #endif
  1376. template<boost::multiprecision::expression_template_option ExpressionTemplates>
  1377. class numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >
  1378. {
  1379. typedef boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> number_type;
  1380. public:
  1381. BOOST_STATIC_CONSTEXPR bool is_specialized = false;
  1382. static number_type (min)() { return number_type(0); }
  1383. static number_type (max)() { return number_type(0); }
  1384. static number_type lowest() { return number_type(0); }
  1385. BOOST_STATIC_CONSTEXPR int digits = 0;
  1386. BOOST_STATIC_CONSTEXPR int digits10 = 0;
  1387. BOOST_STATIC_CONSTEXPR int max_digits10 = 0;
  1388. BOOST_STATIC_CONSTEXPR bool is_signed = false;
  1389. BOOST_STATIC_CONSTEXPR bool is_integer = false;
  1390. BOOST_STATIC_CONSTEXPR bool is_exact = false;
  1391. BOOST_STATIC_CONSTEXPR int radix = 0;
  1392. static number_type epsilon() { return number_type(0); }
  1393. static number_type round_error() { return number_type(0); }
  1394. BOOST_STATIC_CONSTEXPR int min_exponent = 0;
  1395. BOOST_STATIC_CONSTEXPR int min_exponent10 = 0;
  1396. BOOST_STATIC_CONSTEXPR int max_exponent = 0;
  1397. BOOST_STATIC_CONSTEXPR int max_exponent10 = 0;
  1398. BOOST_STATIC_CONSTEXPR bool has_infinity = false;
  1399. BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = false;
  1400. BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false;
  1401. BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent;
  1402. BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false;
  1403. static number_type infinity() { return number_type(0); }
  1404. static number_type quiet_NaN() { return number_type(0); }
  1405. static number_type signaling_NaN() { return number_type(0); }
  1406. static number_type denorm_min() { return number_type(0); }
  1407. BOOST_STATIC_CONSTEXPR bool is_iec559 = false;
  1408. BOOST_STATIC_CONSTEXPR bool is_bounded = false;
  1409. BOOST_STATIC_CONSTEXPR bool is_modulo = false;
  1410. BOOST_STATIC_CONSTEXPR bool traps = false;
  1411. BOOST_STATIC_CONSTEXPR bool tinyness_before = false;
  1412. BOOST_STATIC_CONSTEXPR float_round_style round_style = round_toward_zero;
  1413. };
  1414. #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
  1415. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1416. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::digits;
  1417. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1418. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::digits10;
  1419. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1420. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::max_digits10;
  1421. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1422. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::is_signed;
  1423. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1424. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::is_integer;
  1425. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1426. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::is_exact;
  1427. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1428. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::radix;
  1429. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1430. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::min_exponent;
  1431. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1432. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::min_exponent10;
  1433. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1434. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::max_exponent;
  1435. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1436. BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::max_exponent10;
  1437. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1438. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::has_infinity;
  1439. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1440. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::has_quiet_NaN;
  1441. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1442. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::has_signaling_NaN;
  1443. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1444. BOOST_CONSTEXPR_OR_CONST float_denorm_style numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::has_denorm;
  1445. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1446. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::has_denorm_loss;
  1447. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1448. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::is_iec559;
  1449. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1450. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::is_bounded;
  1451. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1452. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::is_modulo;
  1453. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1454. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::traps;
  1455. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1456. BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::tinyness_before;
  1457. template <boost::multiprecision::expression_template_option ExpressionTemplates>
  1458. BOOST_CONSTEXPR_OR_CONST float_round_style numeric_limits<boost::multiprecision::number<boost::multiprecision::mpfi_float_backend<0>, ExpressionTemplates> >::round_style;
  1459. #endif
  1460. } // namespace std
  1461. #endif