comparison.hpp 18 KB

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