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{
14 // This is the key addition routine where all the argument types are non-trivial cpp_int's:
16 template <class CppInt1, class CppInt2, class CppInt3>
17 inline void add_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) BOOST_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
21 // Nothing fancy, just let uintmax_t take the strain:
22 double_limb_type carry = 0;
24 unsigned as = a.size();
25 unsigned bs = b.size();
30 result = static_cast<double_limb_type>(*a.limbs()) + static_cast<double_limb_type>(*b.limbs());
35 typename CppInt2::const_limb_pointer pa = a.limbs();
36 typename CppInt3::const_limb_pointer pb = b.limbs();
37 typename CppInt1::limb_pointer pr = result.limbs();
38 typename CppInt1::limb_pointer pr_end = pr + m;
43 // First where a and b overlap:
46 carry += static_cast<double_limb_type>(*pa) + static_cast<double_limb_type>(*pb);
47 *pr = static_cast<limb_type>(carry);
48 carry >>= CppInt1::limb_bits;
52 // Now where only a has digits:
58 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1600)
59 std::copy(pa, pa + (pr_end - pr), stdext::checked_array_iterator<limb_type*>(pr, result.size()));
61 std::copy(pa, pa + (pr_end - pr), pr);
65 carry += static_cast<double_limb_type>(*pa);
66 *pr = static_cast<limb_type>(carry);
67 carry >>= CppInt1::limb_bits;
72 // We overflowed, need to add one more limb:
73 result.resize(x + 1, x + 1);
74 if(CppInt1::variable || (result.size() > x))
75 result.limbs()[x] = static_cast<limb_type>(carry);
78 result.sign(a.sign());
81 // As above, but for adding a single limb to a non-trivial cpp_int:
83 template <class CppInt1, class CppInt2>
84 inline void add_unsigned(CppInt1& result, const CppInt2& a, const limb_type& o) BOOST_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
86 // Addition using modular arithmetic.
87 // Nothing fancy, just let uintmax_t take the strain:
89 result.resize(a.size(), a.size());
90 double_limb_type carry = o;
91 typename CppInt1::limb_pointer pr = result.limbs();
92 typename CppInt2::const_limb_pointer pa = a.limbs();
94 // Addition with carry until we either run out of digits or carry is zero:
95 for(; carry && (i < result.size()); ++i)
97 carry += static_cast<double_limb_type>(pa[i]);
98 pr[i] = static_cast<limb_type>(carry);
99 carry >>= CppInt1::limb_bits;
101 // Just copy any remaining digits:
104 for(; i < result.size(); ++i)
109 // We overflowed, need to add one more limb:
110 unsigned x = result.size();
111 result.resize(x + 1, x + 1);
112 if(CppInt1::variable || (result.size() > x))
113 result.limbs()[x] = static_cast<limb_type>(carry);
116 result.sign(a.sign());
119 // Core subtraction routine for all non-trivial cpp_int's:
121 template <class CppInt1, class CppInt2, class CppInt3>
122 inline void subtract_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) BOOST_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
126 // Nothing fancy, just let uintmax_t take the strain:
127 double_limb_type borrow = 0;
129 minmax(a.size(), b.size(), m, x);
131 // special cases for small limb counts:
136 limb_type al = *a.limbs();
137 limb_type bl = *b.limbs();
147 // This isn't used till later, but comparison has to occur before we resize the result,
148 // as that may also resize a or b if this is an inplace operation:
149 int c = a.compare_unsigned(b);
150 // Set up the result vector:
152 // Now that a, b, and result are stable, get pointers to their limbs:
153 typename CppInt2::const_limb_pointer pa = a.limbs();
154 typename CppInt3::const_limb_pointer pb = b.limbs();
155 typename CppInt1::limb_pointer pr = result.limbs();
156 bool swapped = false;
164 result = static_cast<limb_type>(0);
169 // First where a and b overlap:
172 borrow = static_cast<double_limb_type>(pa[i]) - static_cast<double_limb_type>(pb[i]) - borrow;
173 pr[i] = static_cast<limb_type>(borrow);
174 borrow = (borrow >> CppInt1::limb_bits) & 1u;
177 // Now where only a has digits, only as long as we've borrowed:
178 while(borrow && (i < x))
180 borrow = static_cast<double_limb_type>(pa[i]) - borrow;
181 pr[i] = static_cast<limb_type>(borrow);
182 borrow = (borrow >> CppInt1::limb_bits) & 1u;
185 // Any remaining digits are the same as those in pa:
186 if((x != i) && (pa != pr))
187 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1600)
188 std::copy(pa + i, pa + x, stdext::checked_array_iterator<limb_type*>(pr + i, result.size() - i));
190 std::copy(pa + i, pa + x, pr + i);
192 BOOST_ASSERT(0 == borrow);
195 // We may have lost digits, if so update limb usage count:
198 result.sign(a.sign());
203 // And again to subtract a single limb:
205 template <class CppInt1, class CppInt2>
206 inline void subtract_unsigned(CppInt1& result, const CppInt2& a, const limb_type& b) BOOST_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
208 // Subtract one limb.
209 // Nothing fancy, just let uintmax_t take the strain:
210 BOOST_STATIC_CONSTANT(double_limb_type, borrow = static_cast<double_limb_type>(CppInt1::max_limb_value) + 1);
211 result.resize(a.size(), a.size());
212 typename CppInt1::limb_pointer pr = result.limbs();
213 typename CppInt2::const_limb_pointer pa = a.limbs();
219 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1600)
220 std::copy(pa + 1, pa + a.size(), stdext::checked_array_iterator<limb_type*>(pr + 1, result.size() - 1));
222 std::copy(pa + 1, pa + a.size(), pr + 1);
224 result.sign(a.sign());
226 else if((result.size() == 1) && (*pr == 0))
228 result.sign(false); // zero is unsigned.
231 else if(result.size() == 1)
234 result.sign(!a.sign());
238 *pr = static_cast<limb_type>((borrow + *pa) - b);
242 pr[i] = CppInt1::max_limb_value;
249 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1600)
250 std::copy(pa + i, pa + a.size(), stdext::checked_array_iterator<limb_type*>(pr + i, result.size() - i));
252 std::copy(pa + i, pa + a.size(), pr + i);
256 result.sign(a.sign());
261 // Now the actual functions called by the front end, all of which forward to one of the above:
263 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>
264 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
266 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
267 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
269 eval_add(result, result, o);
271 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>
272 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
274 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
275 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
276 const cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3>& b) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
278 if(a.sign() != b.sign())
280 subtract_unsigned(result, a, b);
283 add_unsigned(result, a, b);
285 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
286 BOOST_MP_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
287 eval_add(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result, const limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
291 subtract_unsigned(result, result, o);
294 add_unsigned(result, result, o);
296 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>
297 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
299 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
300 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
301 const limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
305 subtract_unsigned(result, a, o);
308 add_unsigned(result, a, o);
310 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
311 BOOST_MP_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
313 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
314 const signed_limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
317 eval_subtract(result, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
319 eval_add(result, static_cast<limb_type>(o));
321 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>
322 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
324 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
325 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
326 const signed_limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
329 eval_subtract(result, a, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
331 eval_add(result, a, static_cast<limb_type>(o));
332 else if(&result != &a)
335 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
336 BOOST_MP_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
338 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
339 const limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
343 add_unsigned(result, result, o);
346 subtract_unsigned(result, result, o);
348 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>
349 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
351 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
352 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
353 const limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
357 add_unsigned(result, a, o);
361 subtract_unsigned(result, a, o);
364 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
365 BOOST_MP_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
367 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
368 const signed_limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
373 eval_add(result, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
375 eval_subtract(result, static_cast<limb_type>(o));
378 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>
379 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
381 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
382 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
383 const signed_limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
388 eval_add(result, a, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
390 eval_subtract(result, a, static_cast<limb_type>(o));
392 else if(&result != &a)
396 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
397 BOOST_MP_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
398 eval_increment(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
400 static const limb_type one = 1;
401 if(!result.sign() && (result.limbs()[0] < cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::max_limb_value))
403 else if(result.sign() && result.limbs()[0])
406 eval_add(result, one);
408 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
409 BOOST_MP_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
410 eval_decrement(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
412 static const limb_type one = 1;
413 if(!result.sign() && result.limbs()[0])
415 else if(result.sign() && (result.limbs()[0] < cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::max_limb_value))
418 eval_subtract(result, one);
420 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>
421 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
423 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
424 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
426 eval_subtract(result, result, o);
428 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>
429 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
431 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
432 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
433 const cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3>& b) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
435 if(a.sign() != b.sign())
437 add_unsigned(result, a, b);
440 subtract_unsigned(result, a, b);
444 // Simple addition and subtraction routine for trivial cpp_int's come last:
446 // One of the arguments is signed:
448 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
449 inline typename enable_if_c<
450 is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
451 && is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
452 && (is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value || is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value)
455 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
456 const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
458 if(result.sign() != o.sign())
460 if(*o.limbs() > *result.limbs())
462 *result.limbs() = detail::checked_subtract(*o.limbs(), *result.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
466 *result.limbs() = detail::checked_subtract(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
469 *result.limbs() = detail::checked_add(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
472 // Simple version for two unsigned arguments:
473 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
474 BOOST_MP_FORCEINLINE typename enable_if_c<
475 is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
476 && is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
477 && is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
478 && is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
480 eval_add(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
481 const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
483 *result.limbs() = detail::checked_add(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
487 // signed subtraction:
488 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
489 inline typename enable_if_c<
490 is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
491 && is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
492 && (is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value || is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value)
495 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
496 const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
498 if(result.sign() != o.sign())
500 *result.limbs() = detail::checked_add(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
502 else if(*result.limbs() < *o.limbs())
504 *result.limbs() = detail::checked_subtract(*o.limbs(), *result.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
508 *result.limbs() = detail::checked_subtract(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
512 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
513 BOOST_MP_FORCEINLINE typename enable_if_c<
514 is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
515 && is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
516 && is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
517 && is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
520 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
521 const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
523 *result.limbs() = detail::checked_subtract(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());