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