comparison.hpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. ///////////////////////////////////////////////////////////////
  2. // Copyright 2012 John Maddock. Distributed under the Boost
  3. // Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
  5. //
  6. // Comparison operators for cpp_int_backend:
  7. //
  8. #ifndef BOOST_MP_CPP_INT_COMPARISON_HPP
  9. #define BOOST_MP_CPP_INT_COMPARISON_HPP
  10. #include <boost/type_traits/make_unsigned.hpp>
  11. #include <boost/multiprecision/detail/constexpr.hpp>
  12. namespace boost { namespace multiprecision { namespace backends {
  13. #ifdef BOOST_MSVC
  14. #pragma warning(push)
  15. #pragma warning(disable : 4018 4389 4996)
  16. #endif
  17. //
  18. // Start with non-trivial cpp_int's:
  19. //
  20. template <unsigned MinBits, unsigned MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked, class Allocator>
  21. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  22. !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::value,
  23. bool>::type
  24. eval_eq(const cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>& a, const cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>& b) BOOST_NOEXCEPT
  25. {
  26. return (a.sign() == b.sign()) && (a.size() == b.size()) && std_constexpr::equal(a.limbs(), a.limbs() + a.size(), b.limbs());
  27. }
  28. template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
  29. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  30. !is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value,
  31. bool>::type
  32. eval_eq(const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& a, const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& b) BOOST_NOEXCEPT
  33. {
  34. return (a.sign() == b.sign()) && (a.size() == b.size()) && std_constexpr::equal(a.limbs(), a.limbs() + a.size(), b.limbs());
  35. }
  36. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
  37. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  38. !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator> >::value,
  39. bool>::type
  40. eval_eq(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
  41. {
  42. return (a.sign() == false) && (a.size() == 1) && (*a.limbs() == b);
  43. }
  44. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
  45. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  46. !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator> >::value,
  47. bool>::type
  48. eval_eq(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
  49. {
  50. return (a.sign() == (b < 0)) && (a.size() == 1) && (*a.limbs() == boost::multiprecision::detail::unsigned_abs(b));
  51. }
  52. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
  53. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  54. !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
  55. bool>::type
  56. eval_eq(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
  57. {
  58. return (a.size() == 1) && (*a.limbs() == b);
  59. }
  60. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
  61. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  62. !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
  63. bool>::type
  64. eval_eq(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
  65. {
  66. return (b < 0) ? eval_eq(a, cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>(b)) : eval_eq(a, static_cast<limb_type>(b)); // Use bit pattern of b for comparison
  67. }
  68. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
  69. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  70. !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator> >::value,
  71. bool>::type
  72. eval_lt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
  73. {
  74. if (a.sign())
  75. return true;
  76. if (a.size() > 1)
  77. return false;
  78. return *a.limbs() < b;
  79. }
  80. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
  81. inline BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  82. !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator> >::value,
  83. bool>::type
  84. eval_lt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
  85. {
  86. if ((b == 0) || (a.sign() != (b < 0)))
  87. return a.sign();
  88. if (a.sign())
  89. {
  90. if (a.size() > 1)
  91. return true;
  92. return *a.limbs() > boost::multiprecision::detail::unsigned_abs(b);
  93. }
  94. else
  95. {
  96. if (a.size() > 1)
  97. return false;
  98. return *a.limbs() < boost::multiprecision::detail::unsigned_abs(b);
  99. }
  100. }
  101. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
  102. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  103. !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
  104. bool>::type
  105. eval_lt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
  106. {
  107. if (a.size() > 1)
  108. return false;
  109. return *a.limbs() < b;
  110. }
  111. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
  112. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  113. !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
  114. bool>::type
  115. eval_lt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
  116. {
  117. return (b < 0) ? a.compare(b) < 0 : eval_lt(a, static_cast<limb_type>(b)); // Use bit pattern of b for comparison
  118. }
  119. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
  120. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  121. !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator> >::value,
  122. bool>::type
  123. eval_gt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
  124. {
  125. if (a.sign())
  126. return false;
  127. if (a.size() > 1)
  128. return true;
  129. return *a.limbs() > b;
  130. }
  131. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
  132. inline BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  133. !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
  134. bool>::type
  135. eval_gt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
  136. {
  137. if (b == 0)
  138. return !a.sign() && ((a.size() > 1) || *a.limbs());
  139. if (a.sign() != (b < 0))
  140. return !a.sign();
  141. if (a.sign())
  142. {
  143. if (a.size() > 1)
  144. return false;
  145. return *a.limbs() < boost::multiprecision::detail::unsigned_abs(b);
  146. }
  147. else
  148. {
  149. if (a.size() > 1)
  150. return true;
  151. return *a.limbs() > boost::multiprecision::detail::unsigned_abs(b);
  152. }
  153. }
  154. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
  155. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  156. !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
  157. bool>::type
  158. eval_gt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
  159. {
  160. if (a.size() > 1)
  161. return true;
  162. return *a.limbs() > b;
  163. }
  164. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
  165. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  166. !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
  167. bool>::type
  168. eval_gt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
  169. {
  170. return (b < 0) ? a.compare(b) > 0 : eval_gt(a, static_cast<limb_type>(b)); // Use bit pattern of b for comparison.
  171. }
  172. //
  173. // And again for trivial cpp_ints:
  174. //
  175. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
  176. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  177. is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
  178. bool>::value
  179. eval_eq(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& b) BOOST_NOEXCEPT
  180. {
  181. return (a.sign() == b.sign()) && (*a.limbs() == *b.limbs());
  182. }
  183. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
  184. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  185. is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
  186. bool>::value
  187. eval_eq(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& b) BOOST_NOEXCEPT
  188. {
  189. return *a.limbs() == *b.limbs();
  190. }
  191. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
  192. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  193. is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
  194. bool>::type
  195. eval_eq(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
  196. {
  197. return !a.sign() && (*a.limbs() == b);
  198. }
  199. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
  200. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  201. is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
  202. bool>::type
  203. eval_eq(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
  204. {
  205. return (a.sign() == (b < 0)) && (*a.limbs() == boost::multiprecision::detail::unsigned_abs(b));
  206. }
  207. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
  208. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  209. is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
  210. bool>::type
  211. eval_eq(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
  212. {
  213. return *a.limbs() == b;
  214. }
  215. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
  216. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  217. is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
  218. bool>::type
  219. eval_eq(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
  220. {
  221. typedef typename make_unsigned<S>::type ui_type;
  222. if (b < 0)
  223. {
  224. cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> t(b);
  225. return *a.limbs() == *t.limbs();
  226. }
  227. else
  228. {
  229. return *a.limbs() == static_cast<ui_type>(b);
  230. }
  231. }
  232. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
  233. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  234. is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
  235. bool>::type
  236. eval_lt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& b) BOOST_NOEXCEPT
  237. {
  238. if (a.sign() != b.sign())
  239. return a.sign();
  240. return a.sign() ? *a.limbs() > *b.limbs() : *a.limbs() < *b.limbs();
  241. }
  242. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
  243. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  244. is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
  245. bool>::type
  246. eval_lt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& b) BOOST_NOEXCEPT
  247. {
  248. return *a.limbs() < *b.limbs();
  249. }
  250. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
  251. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  252. is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
  253. bool>::type
  254. eval_lt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
  255. {
  256. if (a.sign())
  257. return true;
  258. return *a.limbs() < b;
  259. }
  260. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
  261. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  262. is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
  263. bool>::type
  264. eval_lt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
  265. {
  266. if (a.sign() != (b < 0))
  267. return a.sign();
  268. return a.sign() ? (*a.limbs() > boost::multiprecision::detail::unsigned_abs(b)) : (*a.limbs() < boost::multiprecision::detail::unsigned_abs(b));
  269. }
  270. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
  271. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  272. is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
  273. bool>::type
  274. eval_lt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
  275. {
  276. return *a.limbs() < b;
  277. }
  278. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
  279. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  280. is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
  281. bool>::type
  282. eval_lt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
  283. {
  284. typedef typename make_unsigned<S>::type ui_type;
  285. if (b < 0)
  286. {
  287. cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> t(b);
  288. return *a.limbs() < *t.limbs();
  289. }
  290. else
  291. {
  292. return *a.limbs() < static_cast<ui_type>(b);
  293. }
  294. }
  295. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
  296. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  297. is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
  298. bool>::type
  299. eval_gt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& b) BOOST_NOEXCEPT
  300. {
  301. if (a.sign() != b.sign())
  302. return !a.sign();
  303. return a.sign() ? *a.limbs() < *b.limbs() : *a.limbs() > *b.limbs();
  304. }
  305. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
  306. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  307. is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
  308. bool>::type
  309. eval_gt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& b) BOOST_NOEXCEPT
  310. {
  311. return *a.limbs() > *b.limbs();
  312. }
  313. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
  314. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  315. is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
  316. bool>::type
  317. eval_gt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
  318. {
  319. if (a.sign())
  320. return false;
  321. return *a.limbs() > b;
  322. }
  323. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
  324. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  325. is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
  326. bool>::type
  327. eval_gt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
  328. {
  329. if (a.sign() != (b < 0))
  330. return !a.sign();
  331. return a.sign() ? (*a.limbs() < boost::multiprecision::detail::unsigned_abs(b)) : (*a.limbs() > boost::multiprecision::detail::unsigned_abs(b));
  332. }
  333. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
  334. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  335. is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
  336. bool>::type
  337. eval_gt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
  338. {
  339. return *a.limbs() > b;
  340. }
  341. template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
  342. BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
  343. is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
  344. bool>::type
  345. eval_gt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
  346. {
  347. typedef typename make_unsigned<S>::type ui_type;
  348. if (b < 0)
  349. {
  350. cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> t(b);
  351. return *a.limbs() > *t.limbs();
  352. }
  353. else
  354. {
  355. return *a.limbs() > static_cast<ui_type>(b);
  356. }
  357. }
  358. #ifdef BOOST_MSVC
  359. #pragma warning(pop)
  360. #endif
  361. }}} // namespace boost::multiprecision::backends
  362. #endif