1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
| ///////////////////////////////////////////////////////////////
| // Copyright 2012 John Maddock. Distributed under the Boost
| // Software License, Version 1.0. (See accompanying file
| // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
| //
| // Comparison operators for cpp_int_backend:
| //
| #ifndef BOOST_MP_CPP_INT_ADD_HPP
| #define BOOST_MP_CPP_INT_ADD_HPP
|
| #include <boost/multiprecision/detail/constexpr.hpp>
| #include <boost/multiprecision/cpp_int/add_unsigned.hpp>
|
| namespace boost { namespace multiprecision { namespace backends {
|
| #ifdef _MSC_VER
| #pragma warning(push)
| #pragma warning(disable : 4127) // conditional expression is constant
| #endif
|
| //
| // As above, but for adding a single limb to a non-trivial cpp_int:
| //
| template <class CppInt1, class CppInt2>
| 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)
| {
| // Addition using modular arithmetic.
| // Nothing fancy, just let uintmax_t take the strain:
| if (&result != &a)
| result.resize(a.size(), a.size());
| double_limb_type carry = o;
| typename CppInt1::limb_pointer pr = result.limbs();
| typename CppInt2::const_limb_pointer pa = a.limbs();
| unsigned i = 0;
| // Addition with carry until we either run out of digits or carry is zero:
| for (; carry && (i < result.size()); ++i)
| {
| carry += static_cast<double_limb_type>(pa[i]);
| #ifdef __MSVC_RUNTIME_CHECKS
| pr[i] = static_cast<limb_type>(carry & ~static_cast<limb_type>(0));
| #else
| pr[i] = static_cast<limb_type>(carry);
| #endif
| carry >>= CppInt1::limb_bits;
| }
| // Just copy any remaining digits:
| if (&a != &result)
| {
| std_constexpr::copy(pa + i, pa + a.size(), pr + i);
| }
| if (carry)
| {
| // We overflowed, need to add one more limb:
| unsigned x = result.size();
| result.resize(x + 1, x + 1);
| if (result.size() > x)
| result.limbs()[x] = static_cast<limb_type>(carry);
| }
| result.normalize();
| result.sign(a.sign());
| }
| //
| // And again to subtract a single limb:
| //
| template <class CppInt1, class CppInt2>
| 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)
| {
| // Subtract one limb.
| // Nothing fancy, just let uintmax_t take the strain:
| #ifdef BOOST_NO_CXX14_CONSTEXPR
| BOOST_STATIC_CONSTANT(double_limb_type, borrow = static_cast<double_limb_type>(CppInt1::max_limb_value) + 1);
| #else
| constexpr double_limb_type borrow = static_cast<double_limb_type>(CppInt1::max_limb_value) + 1;
| #endif
| result.resize(a.size(), a.size());
| typename CppInt1::limb_pointer pr = result.limbs();
| typename CppInt2::const_limb_pointer pa = a.limbs();
| if (*pa >= b)
| {
| *pr = *pa - b;
| if (&result != &a)
| {
| std_constexpr::copy(pa + 1, pa + a.size(), pr + 1);
| result.sign(a.sign());
| }
| else if ((result.size() == 1) && (*pr == 0))
| {
| result.sign(false); // zero is unsigned.
| }
| }
| else if (result.size() == 1)
| {
| *pr = b - *pa;
| result.sign(!a.sign());
| }
| else
| {
| *pr = static_cast<limb_type>((borrow + *pa) - b);
| unsigned i = 1;
| while (!pa[i])
| {
| pr[i] = CppInt1::max_limb_value;
| ++i;
| }
| pr[i] = pa[i] - 1;
| if (&result != &a)
| {
| ++i;
| std_constexpr::copy(pa + i, pa + a.size(), pr + i);
| }
| result.normalize();
| result.sign(a.sign());
| }
| }
|
| //
| // Now the actual functions called by the front end, all of which forward to one of the above:
| //
| 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>
| 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
| eval_add(
| cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
| 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))
| {
| eval_add(result, result, o);
| }
| 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>
| 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
| eval_add(
| cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
| const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
| 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))
| {
| if (a.sign() != b.sign())
| {
| subtract_unsigned(result, a, b);
| return;
| }
| add_unsigned(result, a, b);
| }
| template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
| 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
| 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))
| {
| if (result.sign())
| {
| subtract_unsigned(result, result, o);
| }
| else
| add_unsigned(result, result, o);
| }
| 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>
| 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
| eval_add(
| cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
| const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
| const limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
| {
| if (a.sign())
| {
| subtract_unsigned(result, a, o);
| }
| else
| add_unsigned(result, a, o);
| }
| template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
| 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
| eval_add(
| cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
| const signed_limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
| {
| if (o < 0)
| eval_subtract(result, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
| else if (o > 0)
| eval_add(result, static_cast<limb_type>(o));
| }
| 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>
| 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
| eval_add(
| cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
| const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
| const signed_limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
| {
| if (o < 0)
| eval_subtract(result, a, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
| else if (o > 0)
| eval_add(result, a, static_cast<limb_type>(o));
| else if (&result != &a)
| result = a;
| }
| template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
| 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
| eval_subtract(
| 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))
| {
| if (result.sign())
| {
| add_unsigned(result, result, o);
| }
| else
| subtract_unsigned(result, result, o);
| }
| 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>
| 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
| eval_subtract(
| cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
| const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
| const limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
| {
| if (a.sign())
| {
| add_unsigned(result, a, o);
| }
| else
| {
| subtract_unsigned(result, a, o);
| }
| }
| template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
| 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
| eval_subtract(
| cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
| const signed_limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
| {
| if (o)
| {
| if (o < 0)
| eval_add(result, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
| else
| eval_subtract(result, static_cast<limb_type>(o));
| }
| }
| 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>
| 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
| eval_subtract(
| cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
| const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
| const signed_limb_type& o) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
| {
| if (o)
| {
| if (o < 0)
| eval_add(result, a, static_cast<limb_type>(boost::multiprecision::detail::unsigned_abs(o)));
| else
| eval_subtract(result, a, static_cast<limb_type>(o));
| }
| else if (&result != &a)
| result = a;
| }
|
| template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
| 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
| 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))
| {
| #ifdef BOOST_NO_CXX14_CONSTEXPR
| static const limb_type one = 1;
| #else
| constexpr const limb_type one = 1;
| #endif
| if (!result.sign() && (result.limbs()[0] < cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::max_limb_value))
| ++result.limbs()[0];
| else if (result.sign() && result.limbs()[0])
| {
| --result.limbs()[0];
| if (!result.limbs()[0])
| result.sign(false);
| }
| else
| eval_add(result, one);
| }
| template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
| 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
| 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))
| {
| #ifdef BOOST_NO_CXX14_CONSTEXPR
| static const limb_type one = 1;
| #else
| constexpr const limb_type one = 1;
| #endif
| if (!result.sign() && result.limbs()[0])
| --result.limbs()[0];
| else if (result.sign() && (result.limbs()[0] < cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::max_limb_value))
| ++result.limbs()[0];
| else
| eval_subtract(result, one);
| }
| 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>
| 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
| eval_subtract(
| cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
| 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))
| {
| eval_subtract(result, result, o);
| }
| 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>
| 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
| eval_subtract(
| cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
| const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
| 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))
| {
| if (a.sign() != b.sign())
| {
| add_unsigned(result, a, b);
| return;
| }
| subtract_unsigned(result, a, b);
| }
|
| //
| // Simple addition and subtraction routine for trivial cpp_int's come last:
| //
| // One of the arguments is signed:
| //
| template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
| 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<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
| eval_add(
| cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
| 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))
| {
| if (result.sign() != o.sign())
| {
| if (*o.limbs() > *result.limbs())
| {
| *result.limbs() = detail::checked_subtract(*o.limbs(), *result.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
| result.negate();
| }
| else
| *result.limbs() = detail::checked_subtract(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
| }
| else
| *result.limbs() = detail::checked_add(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
| result.normalize();
| }
| // Simple version for two unsigned arguments:
| template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
| 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<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
| eval_add(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
| 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))
| {
| *result.limbs() = detail::checked_add(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
| result.normalize();
| }
|
| // signed subtraction:
| template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
| 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<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
| eval_subtract(
| cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
| 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))
| {
| if (result.sign() != o.sign())
| {
| *result.limbs() = detail::checked_add(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
| }
| else if (*result.limbs() < *o.limbs())
| {
| *result.limbs() = detail::checked_subtract(*o.limbs(), *result.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
| result.negate();
| }
| else
| *result.limbs() = detail::checked_subtract(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
| result.normalize();
| }
|
| template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
| 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<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
| eval_subtract(
| cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
| 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))
| {
| *result.limbs() = detail::checked_subtract(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
| result.normalize();
| }
|
| #ifdef _MSC_VER
| #pragma warning(pop)
| #endif
|
| }}} // namespace boost::multiprecision::backends
|
| #endif
|
|