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 BOOST_MP_USING_ABS
|
Chris@16
|
76 return (a.sign() == (b < 0))
|
Chris@16
|
77 && (a.size() == 1)
|
Chris@16
|
78 && (*a.limbs() == static_cast<limb_type>(abs(b)));
|
Chris@16
|
79 }
|
Chris@16
|
80 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
Chris@16
|
81 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
82 !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
|
Chris@16
|
83 bool
|
Chris@16
|
84 >::type eval_eq(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
|
Chris@16
|
85 {
|
Chris@16
|
86 return (a.size() == 1)
|
Chris@16
|
87 && (*a.limbs() == b);
|
Chris@16
|
88 }
|
Chris@16
|
89 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
Chris@16
|
90 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
91 !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
|
Chris@16
|
92 bool
|
Chris@16
|
93 >::type eval_eq(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
|
Chris@16
|
94 {
|
Chris@16
|
95 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
|
96 }
|
Chris@16
|
97
|
Chris@16
|
98 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
Chris@16
|
99 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
100 !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator> >::value,
|
Chris@16
|
101 bool
|
Chris@16
|
102 >::type eval_lt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
|
Chris@16
|
103 {
|
Chris@16
|
104 if(a.sign())
|
Chris@16
|
105 return true;
|
Chris@16
|
106 if(a.size() > 1)
|
Chris@16
|
107 return false;
|
Chris@16
|
108 return *a.limbs() < b;
|
Chris@16
|
109 }
|
Chris@16
|
110 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
Chris@16
|
111 inline typename enable_if_c<
|
Chris@16
|
112 !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator> >::value,
|
Chris@16
|
113 bool
|
Chris@16
|
114 >::type eval_lt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
|
Chris@16
|
115 {
|
Chris@16
|
116 BOOST_MP_USING_ABS
|
Chris@16
|
117 if((b == 0) || (a.sign() != (b < 0)))
|
Chris@16
|
118 return a.sign();
|
Chris@16
|
119 if(a.sign())
|
Chris@16
|
120 {
|
Chris@16
|
121 if(a.size() > 1)
|
Chris@16
|
122 return true;
|
Chris@16
|
123 return *a.limbs() > static_cast<limb_type>(abs(b));
|
Chris@16
|
124 }
|
Chris@16
|
125 else
|
Chris@16
|
126 {
|
Chris@16
|
127 if(a.size() > 1)
|
Chris@16
|
128 return false;
|
Chris@16
|
129 return *a.limbs() < static_cast<limb_type>(b);
|
Chris@16
|
130 }
|
Chris@16
|
131 }
|
Chris@16
|
132
|
Chris@16
|
133 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
Chris@16
|
134 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
135 !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
|
Chris@16
|
136 bool
|
Chris@16
|
137 >::type eval_lt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
|
Chris@16
|
138 {
|
Chris@16
|
139 if(a.size() > 1)
|
Chris@16
|
140 return false;
|
Chris@16
|
141 return *a.limbs() < b;
|
Chris@16
|
142 }
|
Chris@16
|
143 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
Chris@16
|
144 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
145 !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
|
Chris@16
|
146 bool
|
Chris@16
|
147 >::type eval_lt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
|
Chris@16
|
148 {
|
Chris@16
|
149 return (b < 0) ? a.compare(b) < 0 : eval_lt(a, static_cast<limb_type>(b)); // Use bit pattern of b for comparison
|
Chris@16
|
150 }
|
Chris@16
|
151
|
Chris@16
|
152 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
Chris@16
|
153 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
154 !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator> >::value,
|
Chris@16
|
155 bool
|
Chris@16
|
156 >::type eval_gt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
|
Chris@16
|
157 {
|
Chris@16
|
158 if(a.sign())
|
Chris@16
|
159 return false;
|
Chris@16
|
160 if(a.size() > 1)
|
Chris@16
|
161 return true;
|
Chris@16
|
162 return *a.limbs() > b;
|
Chris@16
|
163 }
|
Chris@16
|
164 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
Chris@16
|
165 inline typename enable_if_c<
|
Chris@16
|
166 !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
|
Chris@16
|
167 bool
|
Chris@16
|
168 >::type eval_gt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
|
Chris@16
|
169 {
|
Chris@16
|
170 BOOST_MP_USING_ABS
|
Chris@16
|
171 if(b == 0)
|
Chris@16
|
172 return !a.sign() && ((a.size() > 1) || *a.limbs());
|
Chris@16
|
173 if(a.sign() != (b < 0))
|
Chris@16
|
174 return !a.sign();
|
Chris@16
|
175 if(a.sign())
|
Chris@16
|
176 {
|
Chris@16
|
177 if(a.size() > 1)
|
Chris@16
|
178 return false;
|
Chris@16
|
179 return *a.limbs() < static_cast<limb_type>(abs(b));
|
Chris@16
|
180 }
|
Chris@16
|
181 else
|
Chris@16
|
182 {
|
Chris@16
|
183 if(a.size() > 1)
|
Chris@16
|
184 return true;
|
Chris@16
|
185 return *a.limbs() > static_cast<limb_type>(b);
|
Chris@16
|
186 }
|
Chris@16
|
187 }
|
Chris@16
|
188
|
Chris@16
|
189 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
Chris@16
|
190 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
191 !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
|
Chris@16
|
192 bool
|
Chris@16
|
193 >::type eval_gt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
|
Chris@16
|
194 {
|
Chris@16
|
195 if(a.size() > 1)
|
Chris@16
|
196 return true;
|
Chris@16
|
197 return *a.limbs() > b;
|
Chris@16
|
198 }
|
Chris@16
|
199 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
Chris@16
|
200 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
201 !is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
|
Chris@16
|
202 bool
|
Chris@16
|
203 >::type eval_gt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
|
Chris@16
|
204 {
|
Chris@16
|
205 return (b < 0) ? a.compare(b) > 0 : eval_gt(a, static_cast<limb_type>(b)); // Use bit pattern of b for comparison.
|
Chris@16
|
206 }
|
Chris@16
|
207 //
|
Chris@16
|
208 // And again for trivial cpp_ints:
|
Chris@16
|
209 //
|
Chris@16
|
210 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
|
Chris@16
|
211 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
212 is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
Chris@16
|
213 bool
|
Chris@16
|
214 >::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
|
215 {
|
Chris@16
|
216 return (a.sign() == b.sign()) && (*a.limbs() == *b.limbs());
|
Chris@16
|
217 }
|
Chris@16
|
218 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
|
Chris@16
|
219 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
220 is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
Chris@16
|
221 bool
|
Chris@16
|
222 >::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
|
223 {
|
Chris@16
|
224 return *a.limbs() == *b.limbs();
|
Chris@16
|
225 }
|
Chris@16
|
226 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
|
Chris@16
|
227 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
228 is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
Chris@16
|
229 bool
|
Chris@16
|
230 >::type eval_eq(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
|
Chris@16
|
231 {
|
Chris@16
|
232 return !a.sign() && (*a.limbs() == b);
|
Chris@16
|
233 }
|
Chris@16
|
234 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
|
Chris@16
|
235 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
236 is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
Chris@16
|
237 bool
|
Chris@16
|
238 >::type eval_eq(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
|
Chris@16
|
239 {
|
Chris@16
|
240 BOOST_MP_USING_ABS
|
Chris@16
|
241 typedef typename make_unsigned<S>::type ui_type;
|
Chris@16
|
242 return (a.sign() == (b < 0)) && (*a.limbs() == static_cast<ui_type>(abs(b)));
|
Chris@16
|
243 }
|
Chris@16
|
244 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
|
Chris@16
|
245 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
246 is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
Chris@16
|
247 bool
|
Chris@16
|
248 >::type eval_eq(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
|
Chris@16
|
249 {
|
Chris@16
|
250 return *a.limbs() == b;
|
Chris@16
|
251 }
|
Chris@16
|
252 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
|
Chris@16
|
253 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
254 is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
Chris@16
|
255 bool
|
Chris@16
|
256 >::type eval_eq(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
|
Chris@16
|
257 {
|
Chris@16
|
258 typedef typename make_unsigned<S>::type ui_type;
|
Chris@16
|
259 if(b < 0)
|
Chris@16
|
260 {
|
Chris@16
|
261 cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> t(b);
|
Chris@16
|
262 return *a.limbs() == *t.limbs();
|
Chris@16
|
263 }
|
Chris@16
|
264 else
|
Chris@16
|
265 {
|
Chris@16
|
266 return *a.limbs() == static_cast<ui_type>(b);
|
Chris@16
|
267 }
|
Chris@16
|
268 }
|
Chris@16
|
269
|
Chris@16
|
270 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
|
Chris@16
|
271 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
272 is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
Chris@16
|
273 bool
|
Chris@16
|
274 >::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
|
275 {
|
Chris@16
|
276 if(a.sign() != b.sign())
|
Chris@16
|
277 return a.sign();
|
Chris@16
|
278 return a.sign() ? *a.limbs() > *b.limbs() : *a.limbs() < *b.limbs();
|
Chris@16
|
279 }
|
Chris@16
|
280 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
|
Chris@16
|
281 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
282 is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
Chris@16
|
283 bool
|
Chris@16
|
284 >::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
|
285 {
|
Chris@16
|
286 return *a.limbs() < *b.limbs();
|
Chris@16
|
287 }
|
Chris@16
|
288 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
|
Chris@16
|
289 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
290 is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
Chris@16
|
291 bool
|
Chris@16
|
292 >::type eval_lt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
|
Chris@16
|
293 {
|
Chris@16
|
294 if(a.sign())
|
Chris@16
|
295 return true;
|
Chris@16
|
296 return *a.limbs() < b;
|
Chris@16
|
297 }
|
Chris@16
|
298 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
|
Chris@16
|
299 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
300 is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
Chris@16
|
301 bool
|
Chris@16
|
302 >::type eval_lt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
|
Chris@16
|
303 {
|
Chris@16
|
304 BOOST_MP_USING_ABS
|
Chris@16
|
305 typedef typename make_unsigned<S>::type ui_type;
|
Chris@16
|
306 if(a.sign() != (b < 0))
|
Chris@16
|
307 return a.sign();
|
Chris@16
|
308 return a.sign() ? (*a.limbs() > static_cast<ui_type>(abs(b))) : (*a.limbs() < static_cast<ui_type>(abs(b)));
|
Chris@16
|
309 }
|
Chris@16
|
310 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
|
Chris@16
|
311 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
312 is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
Chris@16
|
313 bool
|
Chris@16
|
314 >::type eval_lt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
|
Chris@16
|
315 {
|
Chris@16
|
316 return *a.limbs() < b;
|
Chris@16
|
317 }
|
Chris@16
|
318 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
|
Chris@16
|
319 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
320 is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
Chris@16
|
321 bool
|
Chris@16
|
322 >::type eval_lt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
|
Chris@16
|
323 {
|
Chris@16
|
324 typedef typename make_unsigned<S>::type ui_type;
|
Chris@16
|
325 if(b < 0)
|
Chris@16
|
326 {
|
Chris@16
|
327 cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> t(b);
|
Chris@16
|
328 return *a.limbs() < *t.limbs();
|
Chris@16
|
329 }
|
Chris@16
|
330 else
|
Chris@16
|
331 {
|
Chris@16
|
332 return *a.limbs() < static_cast<ui_type>(b);
|
Chris@16
|
333 }
|
Chris@16
|
334 }
|
Chris@16
|
335
|
Chris@16
|
336 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
|
Chris@16
|
337 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
338 is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
Chris@16
|
339 bool
|
Chris@16
|
340 >::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
|
341 {
|
Chris@16
|
342 if(a.sign() != b.sign())
|
Chris@16
|
343 return !a.sign();
|
Chris@16
|
344 return a.sign() ? *a.limbs() < *b.limbs() : *a.limbs() > *b.limbs();
|
Chris@16
|
345 }
|
Chris@16
|
346 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
|
Chris@16
|
347 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
348 is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
Chris@16
|
349 bool
|
Chris@16
|
350 >::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
|
351 {
|
Chris@16
|
352 return *a.limbs() > *b.limbs();
|
Chris@16
|
353 }
|
Chris@16
|
354 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
|
Chris@16
|
355 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
356 is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
Chris@16
|
357 bool
|
Chris@16
|
358 >::type eval_gt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
|
Chris@16
|
359 {
|
Chris@16
|
360 if(a.sign())
|
Chris@16
|
361 return false;
|
Chris@16
|
362 return *a.limbs() > b;
|
Chris@16
|
363 }
|
Chris@16
|
364 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
|
Chris@16
|
365 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
366 is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
Chris@16
|
367 bool
|
Chris@16
|
368 >::type eval_gt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
|
Chris@16
|
369 {
|
Chris@16
|
370 BOOST_MP_USING_ABS
|
Chris@16
|
371 typedef typename make_unsigned<S>::type ui_type;
|
Chris@16
|
372 if(a.sign() != (b < 0))
|
Chris@16
|
373 return !a.sign();
|
Chris@16
|
374 return a.sign() ? (*a.limbs() < static_cast<ui_type>(abs(b))) : (*a.limbs() > static_cast<ui_type>(abs(b)));
|
Chris@16
|
375 }
|
Chris@16
|
376 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
|
Chris@16
|
377 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
378 is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
Chris@16
|
379 bool
|
Chris@16
|
380 >::type eval_gt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
|
Chris@16
|
381 {
|
Chris@16
|
382 return *a.limbs() > b;
|
Chris@16
|
383 }
|
Chris@16
|
384 template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
|
Chris@16
|
385 BOOST_MP_FORCEINLINE typename enable_if_c<
|
Chris@16
|
386 is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
Chris@16
|
387 bool
|
Chris@16
|
388 >::type eval_gt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
|
Chris@16
|
389 {
|
Chris@16
|
390 typedef typename make_unsigned<S>::type ui_type;
|
Chris@16
|
391 if(b < 0)
|
Chris@16
|
392 {
|
Chris@16
|
393 cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> t(b);
|
Chris@16
|
394 return *a.limbs() > *t.limbs();
|
Chris@16
|
395 }
|
Chris@16
|
396 else
|
Chris@16
|
397 {
|
Chris@16
|
398 return *a.limbs() > static_cast<ui_type>(b);
|
Chris@16
|
399 }
|
Chris@16
|
400 }
|
Chris@16
|
401
|
Chris@16
|
402 #ifdef BOOST_MSVC
|
Chris@16
|
403 #pragma warning(pop)
|
Chris@16
|
404 #endif
|
Chris@16
|
405
|
Chris@16
|
406 }}} // namespaces
|
Chris@16
|
407
|
Chris@16
|
408 #endif
|