number_base.hpp 71 KB

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