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