number_base.hpp 65 KB

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