number_base.hpp 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651
  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_BIG_NUM_BASE_HPP
  6. #define BOOST_MATH_BIG_NUM_BASE_HPP
  7. #include <limits>
  8. #include <boost/utility/enable_if.hpp>
  9. #include <boost/type_traits/is_convertible.hpp>
  10. #include <boost/type_traits/is_constructible.hpp>
  11. #include <boost/type_traits/decay.hpp>
  12. #ifdef BOOST_MSVC
  13. # pragma warning(push)
  14. # pragma warning(disable:4307)
  15. #endif
  16. #include <boost/lexical_cast.hpp>
  17. #ifdef BOOST_MSVC
  18. # pragma warning(pop)
  19. #endif
  20. #if defined(NDEBUG) && !defined(_DEBUG)
  21. # define BOOST_MP_FORCEINLINE BOOST_FORCEINLINE
  22. #else
  23. # define BOOST_MP_FORCEINLINE inline
  24. #endif
  25. #if (defined(BOOST_GCC) && (BOOST_GCC <= 40700)) || BOOST_WORKAROUND(__SUNPRO_CC, < 0x5140) || (defined(__clang_major__) && (__clang_major__ == 3) && (__clang_minor__ < 5))
  26. # define BOOST_MP_NOEXCEPT_IF(x)
  27. #else
  28. # define BOOST_MP_NOEXCEPT_IF(x) BOOST_NOEXCEPT_IF(x)
  29. #endif
  30. #if defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) || BOOST_WORKAROUND(__SUNPRO_CC, < 0x5140)
  31. #define BOOST_MP_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
  32. #endif
  33. //
  34. // Thread local storage:
  35. // Note fails on Mingw, see https://sourceforge.net/p/mingw-w64/bugs/527/
  36. //
  37. #if !defined(BOOST_NO_CXX11_THREAD_LOCAL) && !defined(BOOST_INTEL) && !defined(__MINGW32__)
  38. # define BOOST_MP_THREAD_LOCAL thread_local
  39. # define BOOST_MP_USING_THREAD_LOCAL
  40. #else
  41. # define BOOST_MP_THREAD_LOCAL
  42. #endif
  43. #ifdef BOOST_MSVC
  44. # pragma warning(push)
  45. # pragma warning(disable:6326)
  46. #endif
  47. namespace boost{
  48. namespace serialization
  49. {
  50. template <class T>
  51. struct nvp;
  52. template<class T>
  53. const nvp< T > make_nvp(const char * name, T & t);
  54. }
  55. namespace multiprecision{
  56. enum expression_template_option
  57. {
  58. et_off = 0,
  59. et_on = 1
  60. };
  61. template <class Backend>
  62. struct expression_template_default
  63. {
  64. static const expression_template_option value = et_on;
  65. };
  66. template <class Backend, expression_template_option ExpressionTemplates = expression_template_default<Backend>::value>
  67. class number;
  68. template <class T>
  69. struct is_number : public mpl::false_ {};
  70. template <class Backend, expression_template_option ExpressionTemplates>
  71. struct is_number<number<Backend, ExpressionTemplates> > : public mpl::true_ {};
  72. template <class T>
  73. struct is_et_number : public mpl::false_ {};
  74. template <class Backend>
  75. struct is_et_number<number<Backend, et_on> > : public mpl::true_ {};
  76. template <class T>
  77. struct is_no_et_number : public mpl::false_ {};
  78. template <class Backend>
  79. struct is_no_et_number<number<Backend, et_off> > : public mpl::true_ {};
  80. namespace detail{
  81. // Forward-declare an expression wrapper
  82. template<class tag, class Arg1 = void, class Arg2 = void, class Arg3 = void, class Arg4 = void>
  83. struct expression;
  84. } // namespace detail
  85. template <class T>
  86. struct is_number_expression : public mpl::false_ {};
  87. template<class tag, class Arg1, class Arg2, class Arg3, class Arg4>
  88. struct is_number_expression<detail::expression<tag, Arg1, Arg2, Arg3, Arg4> > : public mpl::true_ {};
  89. template <class T, class Num>
  90. struct is_compatible_arithmetic_type
  91. : public mpl::bool_<
  92. is_convertible<T, Num>::value
  93. && !is_same<T, Num>::value
  94. && !is_number_expression<T>::value>
  95. {};
  96. namespace detail{
  97. //
  98. // Workaround for missing abs(boost::long_long_type) and abs(__int128) on some compilers:
  99. //
  100. template <class T>
  101. BOOST_CONSTEXPR typename enable_if_c<(is_signed<T>::value || is_floating_point<T>::value), T>::type abs(T t) BOOST_NOEXCEPT
  102. {
  103. // This strange expression avoids a hardware trap in the corner case
  104. // that val is the most negative value permitted in boost::long_long_type.
  105. // See https://svn.boost.org/trac/boost/ticket/9740.
  106. return t < 0 ? T(1u) + T(-(t + 1)) : t;
  107. }
  108. template <class T>
  109. BOOST_CONSTEXPR typename enable_if_c<(is_unsigned<T>::value), T>::type abs(T t) BOOST_NOEXCEPT
  110. {
  111. return t;
  112. }
  113. #define BOOST_MP_USING_ABS using boost::multiprecision::detail::abs;
  114. template <class T>
  115. BOOST_CONSTEXPR typename enable_if_c<(is_signed<T>::value || is_floating_point<T>::value), typename make_unsigned<T>::type>::type unsigned_abs(T t) BOOST_NOEXCEPT
  116. {
  117. // This strange expression avoids a hardware trap in the corner case
  118. // that val is the most negative value permitted in boost::long_long_type.
  119. // See https://svn.boost.org/trac/boost/ticket/9740.
  120. return t < 0 ? static_cast<typename make_unsigned<T>::type>(1u) + static_cast<typename make_unsigned<T>::type>(-(t + 1)) : static_cast<typename make_unsigned<T>::type>(t);
  121. }
  122. template <class T>
  123. BOOST_CONSTEXPR typename enable_if_c<(is_unsigned<T>::value), T>::type unsigned_abs(T t) BOOST_NOEXCEPT
  124. {
  125. return t;
  126. }
  127. //
  128. // Move support:
  129. //
  130. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  131. # define BOOST_MP_MOVE(x) std::move(x)
  132. #else
  133. # define BOOST_MP_MOVE(x) x
  134. #endif
  135. template <class T>
  136. struct bits_of
  137. {
  138. BOOST_STATIC_ASSERT(is_integral<T>::value || is_enum<T>::value || std::numeric_limits<T>::is_specialized);
  139. static const unsigned value =
  140. std::numeric_limits<T>::is_specialized ?
  141. std::numeric_limits<T>::digits
  142. : sizeof(T) * CHAR_BIT - (is_signed<T>::value ? 1 : 0);
  143. };
  144. #if defined(_GLIBCXX_USE_FLOAT128) && defined(BOOST_GCC) && !defined(__STRICT_ANSI__)
  145. template<> struct bits_of<__float128> { static const unsigned value = 113; };
  146. #endif
  147. template <int b>
  148. struct has_enough_bits
  149. {
  150. template <class T>
  151. struct type : public mpl::bool_<bits_of<T>::value>= b>{};
  152. };
  153. template <class Val, class Backend, class Tag>
  154. struct canonical_imp
  155. {
  156. typedef typename remove_cv<typename decay<const Val>::type>::type type;
  157. };
  158. template <class B, class Backend, class Tag>
  159. struct canonical_imp<number<B, et_on>, Backend, Tag>
  160. {
  161. typedef B type;
  162. };
  163. template <class B, class Backend, class Tag>
  164. struct canonical_imp<number<B, et_off>, Backend, Tag>
  165. {
  166. typedef B type;
  167. };
  168. #ifdef __SUNPRO_CC
  169. template <class B, class Backend>
  170. struct canonical_imp<number<B, et_on>, Backend, mpl::int_<3> >
  171. {
  172. typedef B type;
  173. };
  174. template <class B, class Backend>
  175. struct canonical_imp<number<B, et_off>, Backend, mpl::int_<3> >
  176. {
  177. typedef B type;
  178. };
  179. #endif
  180. template <class Val, class Backend>
  181. struct canonical_imp<Val, Backend, mpl::int_<0> >
  182. {
  183. typedef typename has_enough_bits<bits_of<Val>::value>::template type<mpl::_> pred_type;
  184. typedef typename mpl::find_if<
  185. typename Backend::signed_types,
  186. pred_type
  187. >::type iter_type;
  188. typedef typename mpl::end<typename Backend::signed_types>::type end_type;
  189. typedef typename mpl::eval_if<boost::is_same<iter_type, end_type>, mpl::identity<Val>, mpl::deref<iter_type> >::type type;
  190. };
  191. template <class Val, class Backend>
  192. struct canonical_imp<Val, Backend, mpl::int_<1> >
  193. {
  194. typedef typename has_enough_bits<bits_of<Val>::value>::template type<mpl::_> pred_type;
  195. typedef typename mpl::find_if<
  196. typename Backend::unsigned_types,
  197. pred_type
  198. >::type iter_type;
  199. typedef typename mpl::end<typename Backend::unsigned_types>::type end_type;
  200. typedef typename mpl::eval_if<boost::is_same<iter_type, end_type>, mpl::identity<Val>, mpl::deref<iter_type> >::type type;
  201. };
  202. template <class Val, class Backend>
  203. struct canonical_imp<Val, Backend, mpl::int_<2> >
  204. {
  205. typedef typename has_enough_bits<bits_of<Val>::value>::template type<mpl::_> pred_type;
  206. typedef typename mpl::find_if<
  207. typename Backend::float_types,
  208. pred_type
  209. >::type iter_type;
  210. typedef typename mpl::end<typename Backend::float_types>::type end_type;
  211. typedef typename mpl::eval_if<boost::is_same<iter_type, end_type>, mpl::identity<Val>, mpl::deref<iter_type> >::type type;
  212. };
  213. template <class Val, class Backend>
  214. struct canonical_imp<Val, Backend, mpl::int_<3> >
  215. {
  216. typedef const char* type;
  217. };
  218. template <class Val, class Backend>
  219. struct canonical
  220. {
  221. typedef typename mpl::if_<
  222. is_signed<Val>,
  223. mpl::int_<0>,
  224. typename mpl::if_<
  225. is_unsigned<Val>,
  226. mpl::int_<1>,
  227. typename mpl::if_<
  228. is_floating_point<Val>,
  229. mpl::int_<2>,
  230. typename mpl::if_<
  231. mpl::or_<
  232. is_convertible<Val, const char*>,
  233. is_same<Val, std::string>
  234. >,
  235. mpl::int_<3>,
  236. mpl::int_<4>
  237. >::type
  238. >::type
  239. >::type
  240. >::type tag_type;
  241. typedef typename canonical_imp<Val, Backend, tag_type>::type type;
  242. };
  243. struct terminal{};
  244. struct negate{};
  245. struct plus{};
  246. struct minus{};
  247. struct multiplies{};
  248. struct divides{};
  249. struct modulus{};
  250. struct shift_left{};
  251. struct shift_right{};
  252. struct bitwise_and{};
  253. struct bitwise_or{};
  254. struct bitwise_xor{};
  255. struct bitwise_complement{};
  256. struct add_immediates{};
  257. struct subtract_immediates{};
  258. struct multiply_immediates{};
  259. struct divide_immediates{};
  260. struct modulus_immediates{};
  261. struct bitwise_and_immediates{};
  262. struct bitwise_or_immediates{};
  263. struct bitwise_xor_immediates{};
  264. struct complement_immediates{};
  265. struct function{};
  266. struct multiply_add{};
  267. struct multiply_subtract{};
  268. template <class T>
  269. struct backend_type;
  270. template <class T, expression_template_option ExpressionTemplates>
  271. struct backend_type<number<T, ExpressionTemplates> >
  272. {
  273. typedef T type;
  274. };
  275. template <class tag, class A1, class A2, class A3, class A4>
  276. struct backend_type<expression<tag, A1, A2, A3, A4> >
  277. {
  278. typedef typename backend_type<typename expression<tag, A1, A2, A3, A4>::result_type>::type type;
  279. };
  280. template <class T1, class T2>
  281. struct combine_expression
  282. {
  283. #ifdef BOOST_NO_CXX11_DECLTYPE
  284. typedef typename mpl::if_c<(sizeof(T1() + T2()) == sizeof(T1)), T1, T2>::type type;
  285. #else
  286. typedef decltype(T1() + T2()) type;
  287. #endif
  288. };
  289. template <class T1, expression_template_option ExpressionTemplates, class T2>
  290. struct combine_expression<number<T1, ExpressionTemplates>, T2>
  291. {
  292. typedef number<T1, ExpressionTemplates> type;
  293. };
  294. template <class T1, class T2, expression_template_option ExpressionTemplates>
  295. struct combine_expression<T1, number<T2, ExpressionTemplates> >
  296. {
  297. typedef number<T2, ExpressionTemplates> type;
  298. };
  299. template <class T, expression_template_option ExpressionTemplates>
  300. struct combine_expression<number<T, ExpressionTemplates>, number<T, ExpressionTemplates> >
  301. {
  302. typedef number<T, ExpressionTemplates> type;
  303. };
  304. template <class T1, expression_template_option ExpressionTemplates1, class T2, expression_template_option ExpressionTemplates2>
  305. struct combine_expression<number<T1, ExpressionTemplates1>, number<T2, ExpressionTemplates2> >
  306. {
  307. typedef typename mpl::if_c<
  308. is_convertible<number<T2, ExpressionTemplates2>, number<T1, ExpressionTemplates2> >::value,
  309. number<T1, ExpressionTemplates1>,
  310. number<T2, ExpressionTemplates2>
  311. >::type type;
  312. };
  313. template <class T>
  314. struct arg_type
  315. {
  316. typedef expression<terminal, T> type;
  317. };
  318. template <class Tag, class Arg1, class Arg2, class Arg3, class Arg4>
  319. struct arg_type<expression<Tag, Arg1, Arg2, Arg3, Arg4> >
  320. {
  321. typedef expression<Tag, Arg1, Arg2, Arg3, Arg4> type;
  322. };
  323. struct unmentionable
  324. {
  325. unmentionable* proc(){ return 0; }
  326. };
  327. typedef unmentionable* (unmentionable::*unmentionable_type)();
  328. template <class T, bool b>
  329. struct expression_storage_base
  330. {
  331. typedef const T& type;
  332. };
  333. template <class T>
  334. struct expression_storage_base<T, true>
  335. {
  336. typedef T type;
  337. };
  338. template <class T>
  339. struct expression_storage : public expression_storage_base<T, boost::is_arithmetic<T>::value> {};
  340. template <class T>
  341. struct expression_storage<T*>
  342. {
  343. typedef T* type;
  344. };
  345. template <class T>
  346. struct expression_storage<const T*>
  347. {
  348. typedef const T* type;
  349. };
  350. template <class tag, class A1, class A2, class A3, class A4>
  351. struct expression_storage<expression<tag, A1, A2, A3, A4> >
  352. {
  353. typedef expression<tag, A1, A2, A3, A4> type;
  354. };
  355. template<class tag, class Arg1>
  356. struct expression<tag, Arg1, void, void, void>
  357. {
  358. typedef mpl::int_<1> arity;
  359. typedef typename arg_type<Arg1>::type left_type;
  360. typedef typename left_type::result_type left_result_type;
  361. typedef typename left_type::result_type result_type;
  362. typedef tag tag_type;
  363. explicit expression(const Arg1& a) : arg(a) {}
  364. #ifndef BOOST_NO_CXX11_STATIC_ASSERT
  365. //
  366. // If we have static_assert we can give a more useful error message
  367. // than if we simply have no operator defined at all:
  368. //
  369. template <class Other>
  370. expression& operator=(const Other&)
  371. {
  372. // This should always fail:
  373. static_assert(sizeof(Other) == INT_MAX, "You can not assign to a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  374. return *this;
  375. }
  376. expression& operator++()
  377. {
  378. // This should always fail:
  379. static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  380. return *this;
  381. }
  382. expression& operator++(int)
  383. {
  384. // This should always fail:
  385. static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  386. return *this;
  387. }
  388. expression& operator--()
  389. {
  390. // This should always fail:
  391. static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  392. return *this;
  393. }
  394. expression& operator--(int)
  395. {
  396. // This should always fail:
  397. static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  398. return *this;
  399. }
  400. template <class Other>
  401. expression& operator+=(const Other&)
  402. {
  403. // This should always fail:
  404. static_assert(sizeof(Other) == INT_MAX, "You can not use operator+= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  405. return *this;
  406. }
  407. template <class Other>
  408. expression& operator-=(const Other&)
  409. {
  410. // This should always fail:
  411. static_assert(sizeof(Other) == INT_MAX, "You can not use operator-= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  412. return *this;
  413. }
  414. template <class Other>
  415. expression& operator*=(const Other&)
  416. {
  417. // This should always fail:
  418. static_assert(sizeof(Other) == INT_MAX, "You can not use operator*= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  419. return *this;
  420. }
  421. template <class Other>
  422. expression& operator/=(const Other&)
  423. {
  424. // This should always fail:
  425. static_assert(sizeof(Other) == INT_MAX, "You can not use operator/= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  426. return *this;
  427. }
  428. template <class Other>
  429. expression& operator%=(const Other&)
  430. {
  431. // This should always fail:
  432. static_assert(sizeof(Other) == INT_MAX, "You can not use operator%= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  433. return *this;
  434. }
  435. template <class Other>
  436. expression& operator|=(const Other&)
  437. {
  438. // This should always fail:
  439. static_assert(sizeof(Other) == INT_MAX, "You can not use operator|= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  440. return *this;
  441. }
  442. template <class Other>
  443. expression& operator&=(const Other&)
  444. {
  445. // This should always fail:
  446. static_assert(sizeof(Other) == INT_MAX, "You can not use operator&= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  447. return *this;
  448. }
  449. template <class Other>
  450. expression& operator^=(const Other&)
  451. {
  452. // This should always fail:
  453. static_assert(sizeof(Other) == INT_MAX, "You can not use operator^= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  454. return *this;
  455. }
  456. template <class Other>
  457. expression& operator<<=(const Other&)
  458. {
  459. // This should always fail:
  460. static_assert(sizeof(Other) == INT_MAX, "You can not use operator<<= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  461. return *this;
  462. }
  463. template <class Other>
  464. expression& operator>>=(const Other&)
  465. {
  466. // This should always fail:
  467. static_assert(sizeof(Other) == INT_MAX, "You can not use operator>>= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  468. return *this;
  469. }
  470. #endif
  471. left_type left()const { return left_type(arg); }
  472. const Arg1& left_ref()const BOOST_NOEXCEPT { return arg; }
  473. static const unsigned depth = left_type::depth + 1;
  474. #ifndef BOOST_MP_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
  475. # if (defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 7) && !defined(__clang__)) || (defined(BOOST_INTEL) && (BOOST_INTEL <= 1500))
  476. //
  477. // Horrible workaround for gcc-4.6.x which always prefers the template
  478. // operator bool() rather than the non-template operator when converting to
  479. // an arithmetic type:
  480. //
  481. template <class T, typename boost::enable_if<is_same<T, bool>, int>::type = 0>
  482. explicit operator T ()const
  483. {
  484. result_type r(*this);
  485. return static_cast<bool>(r);
  486. }
  487. template <class T, typename boost::disable_if_c<is_same<T, bool>::value || is_void<T>::value || is_number<T>::value, int>::type = 0>
  488. explicit operator T ()const
  489. {
  490. return static_cast<T>(static_cast<result_type>(*this));
  491. }
  492. # else
  493. template <class T
  494. #ifndef __SUNPRO_CC
  495. , typename boost::disable_if_c<is_number<T>::value || is_constructible<T const&, result_type>::value, int>::type = 0
  496. #endif
  497. >
  498. explicit operator T()const
  499. {
  500. return static_cast<T>(static_cast<result_type>(*this));
  501. }
  502. BOOST_MP_FORCEINLINE explicit operator bool()const
  503. {
  504. result_type r(*this);
  505. return static_cast<bool>(r);
  506. }
  507. #if BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40800)
  508. BOOST_MP_FORCEINLINE explicit operator void()const {}
  509. #endif
  510. # endif
  511. #else
  512. operator unmentionable_type()const
  513. {
  514. result_type r(*this);
  515. return r ? &unmentionable::proc : 0;
  516. }
  517. #endif
  518. template <class T>
  519. T convert_to()
  520. {
  521. result_type r(*this);
  522. return r.template convert_to<T>();
  523. }
  524. private:
  525. typename expression_storage<Arg1>::type arg;
  526. expression& operator=(const expression&);
  527. };
  528. template<class Arg1>
  529. struct expression<terminal, Arg1, void, void, void>
  530. {
  531. typedef mpl::int_<0> arity;
  532. typedef Arg1 result_type;
  533. typedef terminal tag_type;
  534. explicit expression(const Arg1& a) : arg(a) {}
  535. #ifndef BOOST_NO_CXX11_STATIC_ASSERT
  536. //
  537. // If we have static_assert we can give a more useful error message
  538. // than if we simply have no operator defined at all:
  539. //
  540. template <class Other>
  541. expression& operator=(const Other&)
  542. {
  543. // This should always fail:
  544. static_assert(sizeof(Other) == INT_MAX, "You can not assign to a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  545. return *this;
  546. }
  547. expression& operator++()
  548. {
  549. // This should always fail:
  550. static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  551. return *this;
  552. }
  553. expression& operator++(int)
  554. {
  555. // This should always fail:
  556. static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  557. return *this;
  558. }
  559. expression& operator--()
  560. {
  561. // This should always fail:
  562. static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  563. return *this;
  564. }
  565. expression& operator--(int)
  566. {
  567. // This should always fail:
  568. static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  569. return *this;
  570. }
  571. template <class Other>
  572. expression& operator+=(const Other&)
  573. {
  574. // This should always fail:
  575. static_assert(sizeof(Other) == INT_MAX, "You can not use operator+= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  576. return *this;
  577. }
  578. template <class Other>
  579. expression& operator-=(const Other&)
  580. {
  581. // This should always fail:
  582. static_assert(sizeof(Other) == INT_MAX, "You can not use operator-= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  583. return *this;
  584. }
  585. template <class Other>
  586. expression& operator*=(const Other&)
  587. {
  588. // This should always fail:
  589. static_assert(sizeof(Other) == INT_MAX, "You can not use operator*= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  590. return *this;
  591. }
  592. template <class Other>
  593. expression& operator/=(const Other&)
  594. {
  595. // This should always fail:
  596. static_assert(sizeof(Other) == INT_MAX, "You can not use operator/= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  597. return *this;
  598. }
  599. template <class Other>
  600. expression& operator%=(const Other&)
  601. {
  602. // This should always fail:
  603. static_assert(sizeof(Other) == INT_MAX, "You can not use operator%= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  604. return *this;
  605. }
  606. template <class Other>
  607. expression& operator|=(const Other&)
  608. {
  609. // This should always fail:
  610. static_assert(sizeof(Other) == INT_MAX, "You can not use operator|= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  611. return *this;
  612. }
  613. template <class Other>
  614. expression& operator&=(const Other&)
  615. {
  616. // This should always fail:
  617. static_assert(sizeof(Other) == INT_MAX, "You can not use operator&= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  618. return *this;
  619. }
  620. template <class Other>
  621. expression& operator^=(const Other&)
  622. {
  623. // This should always fail:
  624. static_assert(sizeof(Other) == INT_MAX, "You can not use operator^= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  625. return *this;
  626. }
  627. template <class Other>
  628. expression& operator<<=(const Other&)
  629. {
  630. // This should always fail:
  631. static_assert(sizeof(Other) == INT_MAX, "You can not use operator<<= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  632. return *this;
  633. }
  634. template <class Other>
  635. expression& operator>>=(const Other&)
  636. {
  637. // This should always fail:
  638. static_assert(sizeof(Other) == INT_MAX, "You can not use operator>>= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  639. return *this;
  640. }
  641. #endif
  642. const Arg1& value()const BOOST_NOEXCEPT { return arg; }
  643. static const unsigned depth = 0;
  644. #ifndef BOOST_MP_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
  645. # if (defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 7) && !defined(__clang__)) || (defined(BOOST_INTEL) && (BOOST_INTEL <= 1500))
  646. //
  647. // Horrible workaround for gcc-4.6.x which always prefers the template
  648. // operator bool() rather than the non-template operator when converting to
  649. // an arithmetic type:
  650. //
  651. template <class T, typename boost::enable_if<is_same<T, bool>, int>::type = 0>
  652. explicit operator T ()const
  653. {
  654. result_type r(*this);
  655. return static_cast<bool>(r);
  656. }
  657. template <class T, typename boost::disable_if_c<is_same<T, bool>::value || is_void<T>::value || is_number<T>::value, int>::type = 0>
  658. explicit operator T ()const
  659. {
  660. return static_cast<T>(static_cast<result_type>(*this));
  661. }
  662. # else
  663. template <class T
  664. #ifndef __SUNPRO_CC
  665. , typename boost::disable_if_c<is_number<T>::value || is_constructible<T const&, result_type>::value, int>::type = 0
  666. #endif
  667. >
  668. explicit operator T()const
  669. {
  670. return static_cast<T>(static_cast<result_type>(*this));
  671. }
  672. BOOST_MP_FORCEINLINE explicit operator bool()const
  673. {
  674. result_type r(*this);
  675. return static_cast<bool>(r);
  676. }
  677. #if BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40800)
  678. BOOST_MP_FORCEINLINE explicit operator void()const {}
  679. #endif
  680. # endif
  681. #else
  682. operator unmentionable_type()const
  683. {
  684. return arg ? &unmentionable::proc : 0;
  685. }
  686. #endif
  687. template <class T>
  688. T convert_to()
  689. {
  690. result_type r(*this);
  691. return r.template convert_to<T>();
  692. }
  693. private:
  694. typename expression_storage<Arg1>::type arg;
  695. expression& operator=(const expression&);
  696. };
  697. template <class tag, class Arg1, class Arg2>
  698. struct expression<tag, Arg1, Arg2, void, void>
  699. {
  700. typedef mpl::int_<2> arity;
  701. typedef typename arg_type<Arg1>::type left_type;
  702. typedef typename arg_type<Arg2>::type right_type;
  703. typedef typename left_type::result_type left_result_type;
  704. typedef typename right_type::result_type right_result_type;
  705. typedef typename combine_expression<left_result_type, right_result_type>::type result_type;
  706. typedef tag tag_type;
  707. expression(const Arg1& a1, const Arg2& a2) : arg1(a1), arg2(a2) {}
  708. #ifndef BOOST_NO_CXX11_STATIC_ASSERT
  709. //
  710. // If we have static_assert we can give a more useful error message
  711. // than if we simply have no operator defined at all:
  712. //
  713. template <class Other>
  714. expression& operator=(const Other&)
  715. {
  716. // This should always fail:
  717. static_assert(sizeof(Other) == INT_MAX, "You can not assign to a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  718. return *this;
  719. }
  720. expression& operator++()
  721. {
  722. // This should always fail:
  723. static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  724. return *this;
  725. }
  726. expression& operator++(int)
  727. {
  728. // This should always fail:
  729. static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  730. return *this;
  731. }
  732. expression& operator--()
  733. {
  734. // This should always fail:
  735. static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  736. return *this;
  737. }
  738. expression& operator--(int)
  739. {
  740. // This should always fail:
  741. static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  742. return *this;
  743. }
  744. template <class Other>
  745. expression& operator+=(const Other&)
  746. {
  747. // This should always fail:
  748. static_assert(sizeof(Other) == INT_MAX, "You can not use operator+= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  749. return *this;
  750. }
  751. template <class Other>
  752. expression& operator-=(const Other&)
  753. {
  754. // This should always fail:
  755. static_assert(sizeof(Other) == INT_MAX, "You can not use operator-= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  756. return *this;
  757. }
  758. template <class Other>
  759. expression& operator*=(const Other&)
  760. {
  761. // This should always fail:
  762. static_assert(sizeof(Other) == INT_MAX, "You can not use operator*= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  763. return *this;
  764. }
  765. template <class Other>
  766. expression& operator/=(const Other&)
  767. {
  768. // This should always fail:
  769. static_assert(sizeof(Other) == INT_MAX, "You can not use operator/= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  770. return *this;
  771. }
  772. template <class Other>
  773. expression& operator%=(const Other&)
  774. {
  775. // This should always fail:
  776. static_assert(sizeof(Other) == INT_MAX, "You can not use operator%= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  777. return *this;
  778. }
  779. template <class Other>
  780. expression& operator|=(const Other&)
  781. {
  782. // This should always fail:
  783. static_assert(sizeof(Other) == INT_MAX, "You can not use operator|= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  784. return *this;
  785. }
  786. template <class Other>
  787. expression& operator&=(const Other&)
  788. {
  789. // This should always fail:
  790. static_assert(sizeof(Other) == INT_MAX, "You can not use operator&= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  791. return *this;
  792. }
  793. template <class Other>
  794. expression& operator^=(const Other&)
  795. {
  796. // This should always fail:
  797. static_assert(sizeof(Other) == INT_MAX, "You can not use operator^= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  798. return *this;
  799. }
  800. template <class Other>
  801. expression& operator<<=(const Other&)
  802. {
  803. // This should always fail:
  804. static_assert(sizeof(Other) == INT_MAX, "You can not use operator<<= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  805. return *this;
  806. }
  807. template <class Other>
  808. expression& operator>>=(const Other&)
  809. {
  810. // This should always fail:
  811. static_assert(sizeof(Other) == INT_MAX, "You can not use operator>>= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  812. return *this;
  813. }
  814. #endif
  815. left_type left()const { return left_type(arg1); }
  816. right_type right()const { return right_type(arg2); }
  817. const Arg1& left_ref()const BOOST_NOEXCEPT { return arg1; }
  818. const Arg2& right_ref()const BOOST_NOEXCEPT { return arg2; }
  819. #ifndef BOOST_MP_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
  820. # if (defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 7) && !defined(__clang__)) || (defined(BOOST_INTEL) && (BOOST_INTEL <= 1500))
  821. //
  822. // Horrible workaround for gcc-4.6.x which always prefers the template
  823. // operator bool() rather than the non-template operator when converting to
  824. // an arithmetic type:
  825. //
  826. template <class T, typename boost::enable_if<is_same<T, bool>, int>::type = 0>
  827. explicit operator T ()const
  828. {
  829. result_type r(*this);
  830. return static_cast<bool>(r);
  831. }
  832. template <class T, typename boost::disable_if_c<is_same<T, bool>::value || is_void<T>::value || is_number<T>::value, int>::type = 0>
  833. explicit operator T ()const
  834. {
  835. return static_cast<T>(static_cast<result_type>(*this));
  836. }
  837. # else
  838. template <class T
  839. #ifndef __SUNPRO_CC
  840. , typename boost::disable_if_c<is_number<T>::value || is_constructible<T const&, result_type>::value, int>::type = 0
  841. #endif
  842. >
  843. explicit operator T()const
  844. {
  845. return static_cast<T>(static_cast<result_type>(*this));
  846. }
  847. BOOST_MP_FORCEINLINE explicit operator bool()const
  848. {
  849. result_type r(*this);
  850. return static_cast<bool>(r);
  851. }
  852. #if BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40800)
  853. BOOST_MP_FORCEINLINE explicit operator void()const {}
  854. #endif
  855. # endif
  856. #else
  857. operator unmentionable_type()const
  858. {
  859. result_type r(*this);
  860. return r ? &unmentionable::proc : 0;
  861. }
  862. #endif
  863. template <class T>
  864. T convert_to()
  865. {
  866. result_type r(*this);
  867. return r.template convert_to<T>();
  868. }
  869. static const unsigned left_depth = left_type::depth + 1;
  870. static const unsigned right_depth = right_type::depth + 1;
  871. static const unsigned depth = left_depth > right_depth ? left_depth : right_depth;
  872. private:
  873. typename expression_storage<Arg1>::type arg1;
  874. typename expression_storage<Arg2>::type arg2;
  875. expression& operator=(const expression&);
  876. };
  877. template <class tag, class Arg1, class Arg2, class Arg3>
  878. struct expression<tag, Arg1, Arg2, Arg3, void>
  879. {
  880. typedef mpl::int_<3> arity;
  881. typedef typename arg_type<Arg1>::type left_type;
  882. typedef typename arg_type<Arg2>::type middle_type;
  883. typedef typename arg_type<Arg3>::type right_type;
  884. typedef typename left_type::result_type left_result_type;
  885. typedef typename middle_type::result_type middle_result_type;
  886. typedef typename right_type::result_type right_result_type;
  887. typedef typename combine_expression<
  888. left_result_type,
  889. typename combine_expression<right_result_type, middle_result_type>::type
  890. >::type result_type;
  891. typedef tag tag_type;
  892. expression(const Arg1& a1, const Arg2& a2, const Arg3& a3) : arg1(a1), arg2(a2), arg3(a3) {}
  893. #ifndef BOOST_NO_CXX11_STATIC_ASSERT
  894. //
  895. // If we have static_assert we can give a more useful error message
  896. // than if we simply have no operator defined at all:
  897. //
  898. template <class Other>
  899. expression& operator=(const Other&)
  900. {
  901. // This should always fail:
  902. static_assert(sizeof(Other) == INT_MAX, "You can not assign to a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  903. return *this;
  904. }
  905. expression& operator++()
  906. {
  907. // This should always fail:
  908. static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  909. return *this;
  910. }
  911. expression& operator++(int)
  912. {
  913. // This should always fail:
  914. static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  915. return *this;
  916. }
  917. expression& operator--()
  918. {
  919. // This should always fail:
  920. static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  921. return *this;
  922. }
  923. expression& operator--(int)
  924. {
  925. // This should always fail:
  926. static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  927. return *this;
  928. }
  929. template <class Other>
  930. expression& operator+=(const Other&)
  931. {
  932. // This should always fail:
  933. static_assert(sizeof(Other) == INT_MAX, "You can not use operator+= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  934. return *this;
  935. }
  936. template <class Other>
  937. expression& operator-=(const Other&)
  938. {
  939. // This should always fail:
  940. static_assert(sizeof(Other) == INT_MAX, "You can not use operator-= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  941. return *this;
  942. }
  943. template <class Other>
  944. expression& operator*=(const Other&)
  945. {
  946. // This should always fail:
  947. static_assert(sizeof(Other) == INT_MAX, "You can not use operator*= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  948. return *this;
  949. }
  950. template <class Other>
  951. expression& operator/=(const Other&)
  952. {
  953. // This should always fail:
  954. static_assert(sizeof(Other) == INT_MAX, "You can not use operator/= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  955. return *this;
  956. }
  957. template <class Other>
  958. expression& operator%=(const Other&)
  959. {
  960. // This should always fail:
  961. static_assert(sizeof(Other) == INT_MAX, "You can not use operator%= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  962. return *this;
  963. }
  964. template <class Other>
  965. expression& operator|=(const Other&)
  966. {
  967. // This should always fail:
  968. static_assert(sizeof(Other) == INT_MAX, "You can not use operator|= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  969. return *this;
  970. }
  971. template <class Other>
  972. expression& operator&=(const Other&)
  973. {
  974. // This should always fail:
  975. static_assert(sizeof(Other) == INT_MAX, "You can not use operator&= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  976. return *this;
  977. }
  978. template <class Other>
  979. expression& operator^=(const Other&)
  980. {
  981. // This should always fail:
  982. static_assert(sizeof(Other) == INT_MAX, "You can not use operator^= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  983. return *this;
  984. }
  985. template <class Other>
  986. expression& operator<<=(const Other&)
  987. {
  988. // This should always fail:
  989. static_assert(sizeof(Other) == INT_MAX, "You can not use operator<<= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  990. return *this;
  991. }
  992. template <class Other>
  993. expression& operator>>=(const Other&)
  994. {
  995. // This should always fail:
  996. static_assert(sizeof(Other) == INT_MAX, "You can not use operator>>= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  997. return *this;
  998. }
  999. #endif
  1000. left_type left()const { return left_type(arg1); }
  1001. middle_type middle()const { return middle_type(arg2); }
  1002. right_type right()const { return right_type(arg3); }
  1003. const Arg1& left_ref()const BOOST_NOEXCEPT { return arg1; }
  1004. const Arg2& middle_ref()const BOOST_NOEXCEPT { return arg2; }
  1005. const Arg3& right_ref()const BOOST_NOEXCEPT { return arg3; }
  1006. #ifndef BOOST_MP_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
  1007. # if (defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 7) && !defined(__clang__)) || (defined(BOOST_INTEL) && (BOOST_INTEL <= 1500))
  1008. //
  1009. // Horrible workaround for gcc-4.6.x which always prefers the template
  1010. // operator bool() rather than the non-template operator when converting to
  1011. // an arithmetic type:
  1012. //
  1013. template <class T, typename boost::enable_if<is_same<T, bool>, int>::type = 0>
  1014. explicit operator T ()const
  1015. {
  1016. result_type r(*this);
  1017. return static_cast<bool>(r);
  1018. }
  1019. template <class T, typename boost::disable_if_c<is_same<T, bool>::value || is_void<T>::value || is_number<T>::value, int>::type = 0>
  1020. explicit operator T ()const
  1021. {
  1022. return static_cast<T>(static_cast<result_type>(*this));
  1023. }
  1024. # else
  1025. template <class T
  1026. #ifndef __SUNPRO_CC
  1027. , typename boost::disable_if_c<is_number<T>::value || is_constructible<T const&, result_type>::value, int>::type = 0
  1028. #endif
  1029. >
  1030. explicit operator T()const
  1031. {
  1032. return static_cast<T>(static_cast<result_type>(*this));
  1033. }
  1034. BOOST_MP_FORCEINLINE explicit operator bool()const
  1035. {
  1036. result_type r(*this);
  1037. return static_cast<bool>(r);
  1038. }
  1039. #if BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40800)
  1040. BOOST_MP_FORCEINLINE explicit operator void()const {}
  1041. #endif
  1042. # endif
  1043. #else
  1044. operator unmentionable_type()const
  1045. {
  1046. result_type r(*this);
  1047. return r ? &unmentionable::proc : 0;
  1048. }
  1049. #endif
  1050. template <class T>
  1051. T convert_to()
  1052. {
  1053. result_type r(*this);
  1054. return r.template convert_to<T>();
  1055. }
  1056. static const unsigned left_depth = left_type::depth + 1;
  1057. static const unsigned middle_depth = middle_type::depth + 1;
  1058. static const unsigned right_depth = right_type::depth + 1;
  1059. static const unsigned depth = left_depth > right_depth ? (left_depth > middle_depth ? left_depth : middle_depth) : (right_depth > middle_depth ? right_depth : middle_depth);
  1060. private:
  1061. typename expression_storage<Arg1>::type arg1;
  1062. typename expression_storage<Arg2>::type arg2;
  1063. typename expression_storage<Arg3>::type arg3;
  1064. expression& operator=(const expression&);
  1065. };
  1066. template <class tag, class Arg1, class Arg2, class Arg3, class Arg4>
  1067. struct expression
  1068. {
  1069. typedef mpl::int_<4> arity;
  1070. typedef typename arg_type<Arg1>::type left_type;
  1071. typedef typename arg_type<Arg2>::type left_middle_type;
  1072. typedef typename arg_type<Arg3>::type right_middle_type;
  1073. typedef typename arg_type<Arg4>::type right_type;
  1074. typedef typename left_type::result_type left_result_type;
  1075. typedef typename left_middle_type::result_type left_middle_result_type;
  1076. typedef typename right_middle_type::result_type right_middle_result_type;
  1077. typedef typename right_type::result_type right_result_type;
  1078. typedef typename combine_expression<
  1079. left_result_type,
  1080. typename combine_expression<
  1081. left_middle_result_type,
  1082. typename combine_expression<right_middle_result_type, right_result_type>::type
  1083. >::type
  1084. >::type result_type;
  1085. typedef tag tag_type;
  1086. expression(const Arg1& a1, const Arg2& a2, const Arg3& a3, const Arg4& a4) : arg1(a1), arg2(a2), arg3(a3), arg4(a4) {}
  1087. #ifndef BOOST_NO_CXX11_STATIC_ASSERT
  1088. //
  1089. // If we have static_assert we can give a more useful error message
  1090. // than if we simply have no operator defined at all:
  1091. //
  1092. template <class Other>
  1093. expression& operator=(const Other&)
  1094. {
  1095. // This should always fail:
  1096. static_assert(sizeof(Other) == INT_MAX, "You can not assign to a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  1097. return *this;
  1098. }
  1099. expression& operator++()
  1100. {
  1101. // This should always fail:
  1102. static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  1103. return *this;
  1104. }
  1105. expression& operator++(int)
  1106. {
  1107. // This should always fail:
  1108. static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  1109. return *this;
  1110. }
  1111. expression& operator--()
  1112. {
  1113. // This should always fail:
  1114. static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  1115. return *this;
  1116. }
  1117. expression& operator--(int)
  1118. {
  1119. // This should always fail:
  1120. static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  1121. return *this;
  1122. }
  1123. template <class Other>
  1124. expression& operator+=(const Other&)
  1125. {
  1126. // This should always fail:
  1127. static_assert(sizeof(Other) == INT_MAX, "You can not use operator+= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  1128. return *this;
  1129. }
  1130. template <class Other>
  1131. expression& operator-=(const Other&)
  1132. {
  1133. // This should always fail:
  1134. static_assert(sizeof(Other) == INT_MAX, "You can not use operator-= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  1135. return *this;
  1136. }
  1137. template <class Other>
  1138. expression& operator*=(const Other&)
  1139. {
  1140. // This should always fail:
  1141. static_assert(sizeof(Other) == INT_MAX, "You can not use operator*= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  1142. return *this;
  1143. }
  1144. template <class Other>
  1145. expression& operator/=(const Other&)
  1146. {
  1147. // This should always fail:
  1148. static_assert(sizeof(Other) == INT_MAX, "You can not use operator/= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  1149. return *this;
  1150. }
  1151. template <class Other>
  1152. expression& operator%=(const Other&)
  1153. {
  1154. // This should always fail:
  1155. static_assert(sizeof(Other) == INT_MAX, "You can not use operator%= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  1156. return *this;
  1157. }
  1158. template <class Other>
  1159. expression& operator|=(const Other&)
  1160. {
  1161. // This should always fail:
  1162. static_assert(sizeof(Other) == INT_MAX, "You can not use operator|= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  1163. return *this;
  1164. }
  1165. template <class Other>
  1166. expression& operator&=(const Other&)
  1167. {
  1168. // This should always fail:
  1169. static_assert(sizeof(Other) == INT_MAX, "You can not use operator&= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  1170. return *this;
  1171. }
  1172. template <class Other>
  1173. expression& operator^=(const Other&)
  1174. {
  1175. // This should always fail:
  1176. static_assert(sizeof(Other) == INT_MAX, "You can not use operator^= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  1177. return *this;
  1178. }
  1179. template <class Other>
  1180. expression& operator<<=(const Other&)
  1181. {
  1182. // This should always fail:
  1183. static_assert(sizeof(Other) == INT_MAX, "You can not use operator<<= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  1184. return *this;
  1185. }
  1186. template <class Other>
  1187. expression& operator>>=(const Other&)
  1188. {
  1189. // This should always fail:
  1190. static_assert(sizeof(Other) == INT_MAX, "You can not use operator>>= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?");
  1191. return *this;
  1192. }
  1193. #endif
  1194. left_type left()const { return left_type(arg1); }
  1195. left_middle_type left_middle()const { return left_middle_type(arg2); }
  1196. right_middle_type right_middle()const { return right_middle_type(arg3); }
  1197. right_type right()const { return right_type(arg4); }
  1198. const Arg1& left_ref()const BOOST_NOEXCEPT { return arg1; }
  1199. const Arg2& left_middle_ref()const BOOST_NOEXCEPT { return arg2; }
  1200. const Arg3& right_middle_ref()const BOOST_NOEXCEPT { return arg3; }
  1201. const Arg4& right_ref()const BOOST_NOEXCEPT { return arg4; }
  1202. #ifndef BOOST_MP_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
  1203. # if (defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 7) && !defined(__clang__)) || (defined(BOOST_INTEL) && (BOOST_INTEL <= 1500))
  1204. //
  1205. // Horrible workaround for gcc-4.6.x which always prefers the template
  1206. // operator bool() rather than the non-template operator when converting to
  1207. // an arithmetic type:
  1208. //
  1209. template <class T, typename boost::enable_if<is_same<T, bool>, int>::type = 0>
  1210. explicit operator T ()const
  1211. {
  1212. result_type r(*this);
  1213. return static_cast<bool>(r);
  1214. }
  1215. template <class T, typename boost::disable_if_c<is_same<T, bool>::value || is_void<T>::value || is_number<T>::value, int>::type = 0>
  1216. explicit operator T ()const
  1217. {
  1218. return static_cast<T>(static_cast<result_type>(*this));
  1219. }
  1220. # else
  1221. template <class T
  1222. #ifndef __SUNPRO_CC
  1223. , typename boost::disable_if_c<is_number<T>::value || is_constructible<T const&, result_type>::value, int>::type = 0
  1224. #endif
  1225. >
  1226. explicit operator T()const
  1227. {
  1228. return static_cast<T>(static_cast<result_type>(*this));
  1229. }
  1230. BOOST_MP_FORCEINLINE explicit operator bool()const
  1231. {
  1232. result_type r(*this);
  1233. return static_cast<bool>(r);
  1234. }
  1235. #if BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40800)
  1236. BOOST_MP_FORCEINLINE explicit operator void()const {}
  1237. #endif
  1238. # endif
  1239. #else
  1240. operator unmentionable_type()const
  1241. {
  1242. result_type r(*this);
  1243. return r ? &unmentionable::proc : 0;
  1244. }
  1245. #endif
  1246. template <class T>
  1247. T convert_to()
  1248. {
  1249. result_type r(*this);
  1250. return r.template convert_to<T>();
  1251. }
  1252. static const unsigned left_depth = left_type::depth + 1;
  1253. static const unsigned left_middle_depth = left_middle_type::depth + 1;
  1254. static const unsigned right_middle_depth = right_middle_type::depth + 1;
  1255. static const unsigned right_depth = right_type::depth + 1;
  1256. static const unsigned left_max_depth = left_depth > left_middle_depth ? left_depth : left_middle_depth;
  1257. static const unsigned right_max_depth = right_depth > right_middle_depth ? right_depth : right_middle_depth;
  1258. static const unsigned depth = left_max_depth > right_max_depth ? left_max_depth : right_max_depth;
  1259. private:
  1260. typename expression_storage<Arg1>::type arg1;
  1261. typename expression_storage<Arg2>::type arg2;
  1262. typename expression_storage<Arg3>::type arg3;
  1263. typename expression_storage<Arg4>::type arg4;
  1264. expression& operator=(const expression&);
  1265. };
  1266. template <class T>
  1267. struct digits2
  1268. {
  1269. BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized);
  1270. BOOST_STATIC_ASSERT((std::numeric_limits<T>::radix == 2) || (std::numeric_limits<T>::radix == 10));
  1271. // If we really have so many digits that this fails, then we're probably going to hit other problems anyway:
  1272. BOOST_STATIC_ASSERT(LONG_MAX / 1000 > (std::numeric_limits<T>::digits + 1));
  1273. static const long m_value = std::numeric_limits<T>::radix == 10 ? (((std::numeric_limits<T>::digits + 1) * 1000L) / 301L) : std::numeric_limits<T>::digits;
  1274. static inline BOOST_CONSTEXPR long value()BOOST_NOEXCEPT { return m_value; }
  1275. };
  1276. #ifndef BOOST_MP_MIN_EXPONENT_DIGITS
  1277. #ifdef _MSC_VER
  1278. # define BOOST_MP_MIN_EXPONENT_DIGITS 2
  1279. #else
  1280. # define BOOST_MP_MIN_EXPONENT_DIGITS 2
  1281. #endif
  1282. #endif
  1283. template <class S>
  1284. void format_float_string(S& str, boost::intmax_t my_exp, boost::intmax_t digits, std::ios_base::fmtflags f, bool iszero)
  1285. {
  1286. typedef typename S::size_type size_type;
  1287. bool scientific = (f & std::ios_base::scientific) == std::ios_base::scientific;
  1288. bool fixed = (f & std::ios_base::fixed) == std::ios_base::fixed;
  1289. bool showpoint = (f & std::ios_base::showpoint) == std::ios_base::showpoint;
  1290. bool showpos = (f & std::ios_base::showpos) == std::ios_base::showpos;
  1291. bool neg = str.size() && (str[0] == '-');
  1292. if(neg)
  1293. str.erase(0, 1);
  1294. if(digits == 0)
  1295. {
  1296. digits = (std::max)(str.size(), size_type(16));
  1297. }
  1298. if(iszero || str.empty() || (str.find_first_not_of('0') == S::npos))
  1299. {
  1300. // We will be printing zero, even though the value might not
  1301. // actually be zero (it just may have been rounded to zero).
  1302. str = "0";
  1303. if(scientific || fixed)
  1304. {
  1305. str.append(1, '.');
  1306. str.append(size_type(digits), '0');
  1307. if(scientific)
  1308. str.append("e+00");
  1309. }
  1310. else
  1311. {
  1312. if(showpoint)
  1313. {
  1314. str.append(1, '.');
  1315. if(digits > 1)
  1316. str.append(size_type(digits - 1), '0');
  1317. }
  1318. }
  1319. if(neg)
  1320. str.insert(static_cast<std::string::size_type>(0), 1, '-');
  1321. else if(showpos)
  1322. str.insert(static_cast<std::string::size_type>(0), 1, '+');
  1323. return;
  1324. }
  1325. if(!fixed && !scientific && !showpoint)
  1326. {
  1327. //
  1328. // Suppress trailing zeros:
  1329. //
  1330. std::string::iterator pos = str.end();
  1331. while(pos != str.begin() && *--pos == '0'){}
  1332. if(pos != str.end())
  1333. ++pos;
  1334. str.erase(pos, str.end());
  1335. if(str.empty())
  1336. str = '0';
  1337. }
  1338. else if(!fixed || (my_exp >= 0))
  1339. {
  1340. //
  1341. // Pad out the end with zero's if we need to:
  1342. //
  1343. boost::intmax_t chars = str.size();
  1344. chars = digits - chars;
  1345. if(scientific)
  1346. ++chars;
  1347. if(chars > 0)
  1348. {
  1349. str.append(static_cast<std::string::size_type>(chars), '0');
  1350. }
  1351. }
  1352. if(fixed || (!scientific && (my_exp >= -4) && (my_exp < digits)))
  1353. {
  1354. if(1 + my_exp > static_cast<boost::intmax_t>(str.size()))
  1355. {
  1356. // Just pad out the end with zeros:
  1357. str.append(static_cast<std::string::size_type>(1 + my_exp - str.size()), '0');
  1358. if(showpoint || fixed)
  1359. str.append(".");
  1360. }
  1361. else if(my_exp + 1 < static_cast<boost::intmax_t>(str.size()))
  1362. {
  1363. if(my_exp < 0)
  1364. {
  1365. str.insert(static_cast<std::string::size_type>(0), static_cast<std::string::size_type>(-1 - my_exp), '0');
  1366. str.insert(static_cast<std::string::size_type>(0), "0.");
  1367. }
  1368. else
  1369. {
  1370. // Insert the decimal point:
  1371. str.insert(static_cast<std::string::size_type>(my_exp + 1), 1, '.');
  1372. }
  1373. }
  1374. else if(showpoint || fixed) // we have exactly the digits we require to left of the point
  1375. str += ".";
  1376. if(fixed)
  1377. {
  1378. // We may need to add trailing zeros:
  1379. boost::intmax_t l = str.find('.') + 1;
  1380. l = digits - (str.size() - l);
  1381. if(l > 0)
  1382. str.append(size_type(l), '0');
  1383. }
  1384. }
  1385. else
  1386. {
  1387. BOOST_MP_USING_ABS
  1388. // Scientific format:
  1389. if(showpoint || (str.size() > 1))
  1390. str.insert(static_cast<std::string::size_type>(1u), 1, '.');
  1391. str.append(static_cast<std::string::size_type>(1u), 'e');
  1392. S e = boost::lexical_cast<S>(abs(my_exp));
  1393. if(e.size() < BOOST_MP_MIN_EXPONENT_DIGITS)
  1394. e.insert(static_cast<std::string::size_type>(0), BOOST_MP_MIN_EXPONENT_DIGITS - e.size(), '0');
  1395. if(my_exp < 0)
  1396. e.insert(static_cast<std::string::size_type>(0), 1, '-');
  1397. else
  1398. e.insert(static_cast<std::string::size_type>(0), 1, '+');
  1399. str.append(e);
  1400. }
  1401. if(neg)
  1402. str.insert(static_cast<std::string::size_type>(0), 1, '-');
  1403. else if(showpos)
  1404. str.insert(static_cast<std::string::size_type>(0), 1, '+');
  1405. }
  1406. template <class V>
  1407. void check_shift_range(V val, const mpl::true_&, const mpl::true_&)
  1408. {
  1409. if(val > (std::numeric_limits<std::size_t>::max)())
  1410. BOOST_THROW_EXCEPTION(std::out_of_range("Can not shift by a value greater than std::numeric_limits<std::size_t>::max()."));
  1411. if(val < 0)
  1412. BOOST_THROW_EXCEPTION(std::out_of_range("Can not shift by a negative value."));
  1413. }
  1414. template <class V>
  1415. void check_shift_range(V val, const mpl::false_&, const mpl::true_&)
  1416. {
  1417. if(val < 0)
  1418. BOOST_THROW_EXCEPTION(std::out_of_range("Can not shift by a negative value."));
  1419. }
  1420. template <class V>
  1421. void check_shift_range(V val, const mpl::true_&, const mpl::false_&)
  1422. {
  1423. if(val > (std::numeric_limits<std::size_t>::max)())
  1424. BOOST_THROW_EXCEPTION(std::out_of_range("Can not shift by a value greater than std::numeric_limits<std::size_t>::max()."));
  1425. }
  1426. template <class V>
  1427. void check_shift_range(V, const mpl::false_&, const mpl::false_&) BOOST_NOEXCEPT{}
  1428. template <class T>
  1429. const T& evaluate_if_expression(const T& val) { return val; }
  1430. template <class tag, class Arg1, class Arg2, class Arg3, class Arg4>
  1431. typename expression<tag, Arg1, Arg2, Arg3, Arg4>::result_type evaluate_if_expression(const expression<tag, Arg1, Arg2, Arg3, Arg4>& val) { return val; }
  1432. } // namespace detail
  1433. //
  1434. // Traits class, lets us know what kind of number we have, defaults to a floating point type:
  1435. //
  1436. enum number_category_type
  1437. {
  1438. number_kind_unknown = -1,
  1439. number_kind_integer = 0,
  1440. number_kind_floating_point = 1,
  1441. number_kind_rational = 2,
  1442. number_kind_fixed_point = 3,
  1443. number_kind_complex = 4
  1444. };
  1445. template <class Num, bool, bool>
  1446. struct number_category_base : public mpl::int_<number_kind_unknown> {};
  1447. template <class Num>
  1448. struct number_category_base<Num, true, false> : public mpl::int_<std::numeric_limits<Num>::is_integer ? number_kind_integer : (std::numeric_limits<Num>::max_exponent ? number_kind_floating_point : number_kind_unknown)> {};
  1449. template <class Num>
  1450. struct number_category : public number_category_base<Num, boost::is_class<Num>::value || boost::is_arithmetic<Num>::value, boost::is_abstract<Num>::value> {};
  1451. template <class Backend, expression_template_option ExpressionTemplates>
  1452. struct number_category<number<Backend, ExpressionTemplates> > : public number_category<Backend>{};
  1453. template <class tag, class A1, class A2, class A3, class A4>
  1454. struct number_category<detail::expression<tag, A1, A2, A3, A4> > : public number_category<typename detail::expression<tag, A1, A2, A3, A4>::result_type>{};
  1455. //
  1456. // Specializations for types which do not always have numberic_limits specializations:
  1457. //
  1458. #ifdef BOOST_HAS_INT128
  1459. template <>
  1460. struct number_category<boost::int128_type> : public mpl::int_<number_kind_integer> {};
  1461. template <>
  1462. struct number_category<boost::uint128_type> : public mpl::int_<number_kind_integer> {};
  1463. #endif
  1464. #ifdef BOOST_HAS_FLOAT128
  1465. template <>
  1466. struct number_category<__float128> : public mpl::int_<number_kind_floating_point> {};
  1467. #endif
  1468. template <class T>
  1469. struct component_type { typedef T type; };
  1470. template <class tag, class A1, class A2, class A3, class A4>
  1471. struct component_type<detail::expression<tag, A1, A2, A3, A4> > : public component_type<typename detail::expression<tag, A1, A2, A3, A4>::result_type>{};
  1472. template <class T>
  1473. struct scalar_result_from_possible_complex
  1474. {
  1475. typedef typename mpl::if_c<number_category<T>::value == number_kind_complex,
  1476. typename component_type<T>::type, T>::type type;
  1477. };
  1478. template <class T>
  1479. struct complex_result_from_scalar; // individual backends must specialize this trait.
  1480. template <class T>
  1481. struct is_unsigned_number : public mpl::false_{};
  1482. template <class Backend, expression_template_option ExpressionTemplates>
  1483. struct is_unsigned_number<number<Backend, ExpressionTemplates> > : public is_unsigned_number<Backend> {};
  1484. template <class T>
  1485. struct is_signed_number : public mpl::bool_<!is_unsigned_number<T>::value> {};
  1486. template <class T>
  1487. struct is_interval_number : public mpl::false_ {};
  1488. template <class Backend, expression_template_option ExpressionTemplates>
  1489. struct is_interval_number<number<Backend, ExpressionTemplates> > : public is_interval_number<Backend>{};
  1490. }} // namespaces
  1491. namespace boost{ namespace math{ namespace tools{
  1492. template <class T>
  1493. struct promote_arg;
  1494. template <class tag, class A1, class A2, class A3, class A4>
  1495. struct promote_arg<boost::multiprecision::detail::expression<tag, A1, A2, A3, A4> >
  1496. {
  1497. typedef typename boost::multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type type;
  1498. };
  1499. template <class R, class B, boost::multiprecision::expression_template_option ET>
  1500. inline R real_cast(const boost::multiprecision::number<B, ET>& val)
  1501. {
  1502. return val.template convert_to<R>();
  1503. }
  1504. template <class R, class tag, class A1, class A2, class A3, class A4>
  1505. inline R real_cast(const boost::multiprecision::detail::expression<tag, A1, A2, A3, A4>& val)
  1506. {
  1507. typedef typename boost::multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type val_type;
  1508. return val_type(val).template convert_to<R>();
  1509. }
  1510. }
  1511. namespace constants{
  1512. template <class T>
  1513. struct is_explicitly_convertible_from_string;
  1514. template <class B, boost::multiprecision::expression_template_option ET>
  1515. struct is_explicitly_convertible_from_string<boost::multiprecision::number<B, ET> >
  1516. {
  1517. static const bool value = true;
  1518. };
  1519. }
  1520. }}
  1521. #ifdef BOOST_MSVC
  1522. # pragma warning(pop)
  1523. #endif
  1524. #endif // BOOST_MATH_BIG_NUM_BASE_HPP