1 ///////////////////////////////////////////////////////////////
2 // Copyright 2012 John Maddock. Distributed under the Boost
3 // Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
6 // Comparison operators for cpp_int_backend:
8 #ifndef BOOST_MP_CPP_INT_ADD_HPP
9 #define BOOST_MP_CPP_INT_ADD_HPP
11 #include <boost/multiprecision/detail/constexpr.hpp>
13 namespace boost { namespace multiprecision { namespace backends {
17 #pragma warning(disable : 4127) // conditional expression is constant
21 // This is the key addition routine where all the argument types are non-trivial cpp_int's:
23 template <class CppInt1, class CppInt2, class CppInt3>
24 inline BOOST_MP_CXX14_CONSTEXPR void add_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) BOOST_MP_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
26 using ::boost::multiprecision::std_constexpr::swap;
28 // Nothing fancy, just let uintmax_t take the strain:
29 double_limb_type carry = 0;
31 unsigned as = a.size();
32 unsigned bs = b.size();
37 result = static_cast<double_limb_type>(*a.limbs()) + static_cast<double_limb_type>(*b.limbs());
42 typename CppInt2::const_limb_pointer pa = a.limbs();
43 typename CppInt3::const_limb_pointer pb = b.limbs();
44 typename CppInt1::limb_pointer pr = result.limbs();
45 typename CppInt1::limb_pointer pr_end = pr + m;
50 // First where a and b overlap:
53 carry += static_cast<double_limb_type>(*pa) + static_cast<double_limb_type>(*pb);
54 #ifdef __MSVC_RUNTIME_CHECKS
55 *pr = static_cast<limb_type>(carry & ~static_cast<limb_type>(0));
57 *pr = static_cast<limb_type>(carry);
59 carry >>= CppInt1::limb_bits;
63 // Now where only a has digits:
69 std_constexpr::copy(pa, pa + (pr_end - pr), pr);
72 carry += static_cast<double_limb_type>(*pa);
73 #ifdef __MSVC_RUNTIME_CHECKS
74 *pr = static_cast<limb_type>(carry & ~static_cast<limb_type>(0));
76 *pr = static_cast<limb_type>(carry);
78 carry >>= CppInt1::limb_bits;
83 // We overflowed, need to add one more limb:
84 result.resize(x + 1, x + 1);
85 if (result.size() > x)
86 result.limbs()[x] = static_cast<limb_type>(carry);
89 result.sign(a.sign());
92 // As above, but for adding a single limb to a non-trivial cpp_int:
94 template <class CppInt1, class CppInt2>
95 inline BOOST_MP_CXX14_CONSTEXPR void add_unsigned(CppInt1& result, const CppInt2& a, const limb_type& o) BOOST_MP_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
97 // Addition using modular arithmetic.
98 // Nothing fancy, just let uintmax_t take the strain:
100 result.resize(a.size(), a.size());
101 double_limb_type carry = o;
102 typename CppInt1::limb_pointer pr = result.limbs();
103 typename CppInt2::const_limb_pointer pa = a.limbs();
105 // Addition with carry until we either run out of digits or carry is zero:
106 for (; carry && (i < result.size()); ++i)
108 carry += static_cast<double_limb_type>(pa[i]);
109 #ifdef __MSVC_RUNTIME_CHECKS
110 pr[i] = static_cast<limb_type>(carry & ~static_cast<limb_type>(0));
112 pr[i] = static_cast<limb_type>(carry);
114 carry >>= CppInt1::limb_bits;
116 // Just copy any remaining digits:
119 for (; i < result.size(); ++i)
124 // We overflowed, need to add one more limb:
125 unsigned x = result.size();
126 result.resize(x + 1, x + 1);
127 if (result.size() > x)
128 result.limbs()[x] = static_cast<limb_type>(carry);
131 result.sign(a.sign());
134 // Core subtraction routine for all non-trivial cpp_int's:
136 template <class CppInt1, class CppInt2, class CppInt3>
137 inline BOOST_MP_CXX14_CONSTEXPR void subtract_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) BOOST_MP_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
139 using ::boost::multiprecision::std_constexpr::swap;
141 // Nothing fancy, just let uintmax_t take the strain:
142 double_limb_type borrow = 0;
144 minmax(a.size(), b.size(), m, x);
146 // special cases for small limb counts:
151 limb_type al = *a.limbs();
152 limb_type bl = *b.limbs();
155 ::boost::multiprecision::std_constexpr::swap(al, bl);
162 // This isn't used till later, but comparison has to occur before we resize the result,
163 // as that may also resize a or b if this is an inplace operation:
164 int c = a.compare_unsigned(b);
165 // Set up the result vector:
167 // Now that a, b, and result are stable, get pointers to their limbs:
168 typename CppInt2::const_limb_pointer pa = a.limbs();
169 typename CppInt3::const_limb_pointer pb = b.limbs();
170 typename CppInt1::limb_pointer pr = result.limbs();
171 bool swapped = false;
179 result = static_cast<limb_type>(0);
184 // First where a and b overlap:
187 borrow = static_cast<double_limb_type>(pa[i]) - static_cast<double_limb_type>(pb[i]) - borrow;
188 pr[i] = static_cast<limb_type>(borrow);
189 borrow = (borrow >> CppInt1::limb_bits) & 1u;
192 // Now where only a has digits, only as long as we've borrowed:
193 while (borrow && (i < x))
195 borrow = static_cast<double_limb_type>(pa[i]) - borrow;
196 pr[i] = static_cast<limb_type>(borrow);
197 borrow = (borrow >> CppInt1::limb_bits) & 1u;
200 // Any remaining digits are the same as those in pa:
201 if ((x != i) && (pa != pr))
202 std_constexpr::copy(pa + i, pa + x, pr + i);
203 BOOST_ASSERT(0 == borrow);
206 // We may have lost digits, if so update limb usage count:
209 result.sign(a.sign());
214 // And again to subtract a single limb:
216 template <class CppInt1, class CppInt2>
217 inline BOOST_MP_CXX14_CONSTEXPR void subtract_unsigned(CppInt1& result, const CppInt2& a, const limb_type& b) BOOST_MP_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
219 // Subtract one limb.
220 // Nothing fancy, just let uintmax_t take the strain:
221 #ifdef BOOST_NO_CXX14_CONSTEXPR
222 BOOST_STATIC_CONSTANT(double_limb_type, borrow = static_cast<double_limb_type>(CppInt1::max_limb_value) + 1);
224 constexpr double_limb_type borrow = static_cast<double_limb_type>(CppInt1::max_limb_value) + 1;
226 result.resize(a.size(), a.size());
227 typename CppInt1::limb_pointer pr = result.limbs();
228 typename CppInt2::const_limb_pointer pa = a.limbs();
234 std_constexpr::copy(pa + 1, pa + a.size(), pr + 1);
235 result.sign(a.sign());
237 else if ((result.size() == 1) && (*pr == 0))
239 result.sign(false); // zero is unsigned.
242 else if (result.size() == 1)
245 result.sign(!a.sign());
249 *pr = static_cast<limb_type>((borrow + *pa) - b);
253 pr[i] = CppInt1::max_limb_value;
260 std_constexpr::copy(pa + i, pa + a.size(), pr + i);
263 result.sign(a.sign());
268 // Now the actual functions called by the front end, all of which forward to one of the above:
270 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>
271 BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR 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
273 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
274 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))
276 eval_add(result, result, o);
278 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>
279 inline BOOST_MP_CXX14_CONSTEXPR 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
281 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
282 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
283 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))
285 if (a.sign() != b.sign())
287 subtract_unsigned(result, a, b);
290 add_unsigned(result, a, b);
292 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
293 BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
294 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))
298 subtract_unsigned(result, result, o);
301 add_unsigned(result, result, o);
303 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>
304 BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR 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
306 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
307 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
308 const limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
312 subtract_unsigned(result, a, o);
315 add_unsigned(result, a, o);
317 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
318 BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
320 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
321 const signed_limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
324 eval_subtract(result, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
326 eval_add(result, static_cast<limb_type>(o));
328 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>
329 BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR 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
331 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
332 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
333 const signed_limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
336 eval_subtract(result, a, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
338 eval_add(result, a, static_cast<limb_type>(o));
339 else if (&result != &a)
342 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
343 BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
345 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
346 const limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
350 add_unsigned(result, result, o);
353 subtract_unsigned(result, result, o);
355 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>
356 BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR 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
358 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
359 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
360 const limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
364 add_unsigned(result, a, o);
368 subtract_unsigned(result, a, o);
371 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
372 BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
374 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
375 const signed_limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
380 eval_add(result, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
382 eval_subtract(result, static_cast<limb_type>(o));
385 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>
386 BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR 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
388 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
389 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
390 const signed_limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
395 eval_add(result, a, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
397 eval_subtract(result, a, static_cast<limb_type>(o));
399 else if (&result != &a)
403 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
404 BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
405 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))
407 #ifdef BOOST_NO_CXX14_CONSTEXPR
408 static const limb_type one = 1;
410 constexpr const limb_type one = 1;
412 if (!result.sign() && (result.limbs()[0] < cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::max_limb_value))
414 else if (result.sign() && result.limbs()[0])
417 if (!result.limbs()[0])
421 eval_add(result, one);
423 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
424 BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
425 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))
427 #ifdef BOOST_NO_CXX14_CONSTEXPR
428 static const limb_type one = 1;
430 constexpr const limb_type one = 1;
432 if (!result.sign() && result.limbs()[0])
434 else if (result.sign() && (result.limbs()[0] < cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::max_limb_value))
437 eval_subtract(result, one);
439 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>
440 BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR 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
442 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
443 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))
445 eval_subtract(result, result, o);
447 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>
448 BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR 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
450 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
451 const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
452 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))
454 if (a.sign() != b.sign())
456 add_unsigned(result, a, b);
459 subtract_unsigned(result, a, b);
463 // Simple addition and subtraction routine for trivial cpp_int's come last:
465 // One of the arguments is signed:
467 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
468 inline BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
469 is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && (is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value || is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value)>::type
471 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
472 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))
474 if (result.sign() != o.sign())
476 if (*o.limbs() > *result.limbs())
478 *result.limbs() = detail::checked_subtract(*o.limbs(), *result.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
482 *result.limbs() = detail::checked_subtract(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
485 *result.limbs() = detail::checked_add(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
488 // Simple version for two unsigned arguments:
489 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
490 BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
491 is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
492 eval_add(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
493 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))
495 *result.limbs() = detail::checked_add(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
499 // signed subtraction:
500 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
501 inline BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
502 is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && (is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value || is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value)>::type
504 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
505 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))
507 if (result.sign() != o.sign())
509 *result.limbs() = detail::checked_add(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
511 else if (*result.limbs() < *o.limbs())
513 *result.limbs() = detail::checked_subtract(*o.limbs(), *result.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
517 *result.limbs() = detail::checked_subtract(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
521 template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
522 BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename enable_if_c<
523 is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
525 cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
526 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))
528 *result.limbs() = detail::checked_subtract(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
536 }}} // namespace boost::multiprecision::backends