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_
6 // Comparison operators for cpp_int_backend:
8 #ifndef BOOST_MP_CPP_INT_ADD_HPP
9 #define BOOST_MP_CPP_INT_ADD_HPP
11 namespace boost{ namespace multiprecision{ namespace backends{
15 #pragma warning(disable:4127) // conditional expression is constant
19 // This is the key addition routine where all the argument types are non-trivial cpp_int's:
21 template <class CppInt1, class CppInt2, class CppInt3>
22 inline void add_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) BOOST_MP_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
26 // Nothing fancy, just let uintmax_t take the strain:
27 double_limb_type carry = 0;
29 unsigned as = a.size();
30 unsigned bs = b.size();
35 result = static_cast<double_limb_type>(*a.limbs()) + static_cast<double_limb_type>(*b.limbs());
40 typename CppInt2::const_limb_pointer pa = a.limbs();
41 typename CppInt3::const_limb_pointer pb = b.limbs();
42 typename CppInt1::limb_pointer pr = result.limbs();
43 typename CppInt1::limb_pointer pr_end = pr + m;
48 // First where a and b overlap:
51 carry += static_cast<double_limb_type>(*pa) + static_cast<double_limb_type>(*pb);
52 #ifdef __MSVC_RUNTIME_CHECKS
53 *pr = static_cast<limb_type>(carry & ~static_cast<limb_type>(0));
55 *pr = static_cast<limb_type>(carry);
57 carry >>= CppInt1::limb_bits;
61 // Now where only a has digits:
67 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1600)
68 std::copy(pa, pa + (pr_end - pr), stdext::checked_array_iterator<limb_type*>(pr, result.size()));
70 std::copy(pa, pa + (pr_end - pr), pr);
74 carry += static_cast<double_limb_type>(*pa);
75 #ifdef __MSVC_RUNTIME_CHECKS
76 *pr = static_cast<limb_type>(carry & ~static_cast<limb_type>(0));
78 *pr = static_cast<limb_type>(carry);
80 carry >>= CppInt1::limb_bits;
85 // We overflowed, need to add one more limb:
86 result.resize(x + 1, x + 1);
88 result.limbs()[x] = static_cast<limb_type>(carry);
91 result.sign(a.sign());
94 // As above, but for adding a single limb to a non-trivial cpp_int:
96 template <class CppInt1, class CppInt2>
97 inline void add_unsigned(CppInt1& result, const CppInt2& a, const limb_type& o) BOOST_MP_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
99 // Addition using modular arithmetic.
100 // Nothing fancy, just let uintmax_t take the strain:
102 result.resize(a.size(), a.size());
103 double_limb_type carry = o;
104 typename CppInt1::limb_pointer pr = result.limbs();
105 typename CppInt2::const_limb_pointer pa = a.limbs();
107 // Addition with carry until we either run out of digits or carry is zero:
108 for(; carry && (i < result.size()); ++i)
110 carry += static_cast<double_limb_type>(pa[i]);
111 #ifdef __MSVC_RUNTIME_CHECKS
112 pr[i] = static_cast<limb_type>(carry & ~static_cast<limb_type>(0));
114 pr[i] = static_cast<limb_type>(carry);
116 carry >>= CppInt1::limb_bits;
118 // Just copy any remaining digits:
121 for(; i < result.size(); ++i)
126 // We overflowed, need to add one more limb:
127 unsigned x = result.size();
128 result.resize(x + 1, x + 1);
129 if(result.size() > x)
130 result.limbs()[x] = static_cast<limb_type>(carry);
133 result.sign(a.sign());
136 // Core subtraction routine for all non-trivial cpp_int's:
138 template <class CppInt1, class CppInt2, class CppInt3>
139 inline void subtract_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) BOOST_MP_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
143 // Nothing fancy, just let uintmax_t take the strain:
144 double_limb_type borrow = 0;
146 minmax(a.size(), b.size(), m, x);
148 // special cases for small limb counts:
153 limb_type al = *a.limbs();
154 limb_type bl = *b.limbs();
164 // This isn't used till later, but comparison has to occur before we resize the result,
165 // as that may also resize a or b if this is an inplace operation:
166 int c = a.compare_unsigned(b);
167 // Set up the result vector:
169 // Now that a, b, and result are stable, get pointers to their limbs:
170 typename CppInt2::const_limb_pointer pa = a.limbs();
171 typename CppInt3::const_limb_pointer pb = b.limbs();
172 typename CppInt1::limb_pointer pr = result.limbs();
173 bool swapped = false;
181 result = static_cast<limb_type>(0);
186 // First where a and b overlap:
189 borrow = static_cast<double_limb_type>(pa[i]) - static_cast<double_limb_type>(pb[i]) - borrow;
190 pr[i] = static_cast<limb_type>(borrow);
191 borrow = (borrow >> CppInt1::limb_bits) & 1u;
194 // Now where only a has digits, only as long as we've borrowed:
195 while(borrow && (i < x))
197 borrow = static_cast<double_limb_type>(pa[i]) - borrow;
198 pr[i] = static_cast<limb_type>(borrow);
199 borrow = (borrow >> CppInt1::limb_bits) & 1u;
202 // Any remaining digits are the same as those in pa:
203 if((x != i) && (pa != pr))
204 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1600)
205 std::copy(pa + i, pa + x, stdext::checked_array_iterator<limb_type*>(pr + i, result.size() - i));
207 std::copy(pa + i, pa + x, pr + i);
209 BOOST_ASSERT(0 == borrow);
212 // We may have lost digits, if so update limb usage count:
215 result.sign(a.sign());
220 // And again to subtract a single limb:
222 template <class CppInt1, class CppInt2>
223 inline void subtract_unsigned(CppInt1& result, const CppInt2& a, const limb_type& b) BOOST_MP_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
225 // Subtract one limb.
226 // Nothing fancy, just let uintmax_t take the strain:
227 BOOST_STATIC_CONSTANT(double_limb_type, borrow = static_cast<double_limb_type>(CppInt1::max_limb_value) + 1);
228 result.resize(a.size(), a.size());
229 typename CppInt1::limb_pointer pr = result.limbs();
230 typename CppInt2::const_limb_pointer pa = a.limbs();
236 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1600)
237 std::copy(pa + 1, pa + a.size(), stdext::checked_array_iterator<limb_type*>(pr + 1, result.size() - 1));
239 std::copy(pa + 1, pa + a.size(), pr + 1);
241 result.sign(a.sign());
243 else if((result.size() == 1) && (*pr == 0))
245 result.sign(false); // zero is unsigned.
248 else if(result.size() == 1)
251 result.sign(!a.sign());
255 *pr = static_cast<limb_type>((borrow + *pa) - b);
259 pr[i] = CppInt1::max_limb_value;
266 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1600)
267 std::copy(pa + i, pa + a.size(), stdext::checked_array_iterator<limb_type*>(pr + i, result.size() - i));
269 std::copy(pa + i, pa + a.size(), pr + i);
273 result.sign(a.sign());
278 // Now the actual functions called by the front end, all of which forward to one of the above:
280 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>
281 BOOST_MP_FORCEINLINE typename enable_if_c<!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 >::type
283 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
284 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
286 eval_add(result, result, o);
288 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, unsigned MinBits3, unsigned MaxBits3, cpp_integer_type SignType3, cpp_int_check_type Checked3, class Allocator3>
289 inline typename enable_if_c<!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 && !is_trivial_cpp_int<cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3> >::value >::type
291 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
292 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
293 const cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3>& b) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
295 if(a.sign() != b.sign())
297 subtract_unsigned(result, a, b);
300 add_unsigned(result, a, b);
302 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
303 BOOST_MP_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
304 eval_add(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result, const limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
308 subtract_unsigned(result, result, o);
311 add_unsigned(result, result, o);
313 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>
314 BOOST_MP_FORCEINLINE typename enable_if_c<!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 >::type
316 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
317 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
318 const limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
322 subtract_unsigned(result, a, o);
325 add_unsigned(result, a, o);
327 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
328 BOOST_MP_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
330 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
331 const signed_limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
334 eval_subtract(result, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
336 eval_add(result, static_cast<limb_type>(o));
338 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>
339 BOOST_MP_FORCEINLINE typename enable_if_c<!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 >::type
341 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
342 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
343 const signed_limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
346 eval_subtract(result, a, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
348 eval_add(result, a, static_cast<limb_type>(o));
349 else if(&result != &a)
352 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
353 BOOST_MP_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
355 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
356 const limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
360 add_unsigned(result, result, o);
363 subtract_unsigned(result, result, o);
365 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>
366 BOOST_MP_FORCEINLINE typename enable_if_c<!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 >::type
368 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
369 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
370 const limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
374 add_unsigned(result, a, o);
378 subtract_unsigned(result, a, o);
381 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
382 BOOST_MP_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
384 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
385 const signed_limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
390 eval_add(result, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
392 eval_subtract(result, static_cast<limb_type>(o));
395 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>
396 BOOST_MP_FORCEINLINE typename enable_if_c<!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 >::type
398 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
399 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
400 const signed_limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
405 eval_add(result, a, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
407 eval_subtract(result, a, static_cast<limb_type>(o));
409 else if(&result != &a)
413 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
414 BOOST_MP_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
415 eval_increment(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
417 static const limb_type one = 1;
418 if(!result.sign() && (result.limbs()[0] < cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::max_limb_value))
420 else if(result.sign() && result.limbs()[0])
423 eval_add(result, one);
425 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
426 BOOST_MP_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
427 eval_decrement(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
429 static const limb_type one = 1;
430 if(!result.sign() && result.limbs()[0])
432 else if(result.sign() && (result.limbs()[0] < cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::max_limb_value))
435 eval_subtract(result, one);
437 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>
438 BOOST_MP_FORCEINLINE typename enable_if_c<!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 >::type
440 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
441 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
443 eval_subtract(result, result, o);
445 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, unsigned MinBits3, unsigned MaxBits3, cpp_integer_type SignType3, cpp_int_check_type Checked3, class Allocator3>
446 BOOST_MP_FORCEINLINE typename enable_if_c<!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 && !is_trivial_cpp_int<cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3> >::value >::type
448 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
449 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
450 const cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3>& b) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
452 if(a.sign() != b.sign())
454 add_unsigned(result, a, b);
457 subtract_unsigned(result, a, b);
461 // Simple addition and subtraction routine for trivial cpp_int's come last:
463 // One of the arguments is signed:
465 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
466 inline typename enable_if_c<
467 is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
468 && is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
469 && (is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value || is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value)
472 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
473 const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
475 if(result.sign() != o.sign())
477 if(*o.limbs() > *result.limbs())
479 *result.limbs() = detail::checked_subtract(*o.limbs(), *result.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
483 *result.limbs() = detail::checked_subtract(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
486 *result.limbs() = detail::checked_add(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
489 // Simple version for two unsigned arguments:
490 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
491 BOOST_MP_FORCEINLINE typename enable_if_c<
492 is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
493 && is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
494 && is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
495 && is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
497 eval_add(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
498 const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
500 *result.limbs() = detail::checked_add(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
504 // signed subtraction:
505 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
506 inline typename enable_if_c<
507 is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
508 && is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
509 && (is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value || is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value)
512 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
513 const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
515 if(result.sign() != o.sign())
517 *result.limbs() = detail::checked_add(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
519 else if(*result.limbs() < *o.limbs())
521 *result.limbs() = detail::checked_subtract(*o.limbs(), *result.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
525 *result.limbs() = detail::checked_subtract(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
529 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
530 BOOST_MP_FORCEINLINE typename enable_if_c<
531 is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
532 && is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
533 && is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
534 && is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
537 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
538 const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
540 *result.limbs() = detail::checked_subtract(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());