number_base.hpp 72 KB

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