mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2026-07-28 13:04:25 -04:00
Merge commit 'd361e123c6642006deb4ec4127a5ff1b28d7dd74' into feat-refactor
This commit is contained in:
@@ -84,7 +84,7 @@ inline void add_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) BO
|
||||
{
|
||||
// We overflowed, need to add one more limb:
|
||||
result.resize(x + 1, x + 1);
|
||||
if(CppInt1::variable || (result.size() > x))
|
||||
if(result.size() > x)
|
||||
result.limbs()[x] = static_cast<limb_type>(carry);
|
||||
}
|
||||
result.normalize();
|
||||
@@ -126,7 +126,7 @@ inline void add_unsigned(CppInt1& result, const CppInt2& a, const limb_type& o)
|
||||
// We overflowed, need to add one more limb:
|
||||
unsigned x = result.size();
|
||||
result.resize(x + 1, x + 1);
|
||||
if(CppInt1::variable || (result.size() > x))
|
||||
if(result.size() > x)
|
||||
result.limbs()[x] = static_cast<limb_type>(carry);
|
||||
}
|
||||
result.normalize();
|
||||
@@ -417,8 +417,12 @@ BOOST_MP_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<Mi
|
||||
static const limb_type one = 1;
|
||||
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])
|
||||
else if (result.sign() && result.limbs()[0])
|
||||
{
|
||||
--result.limbs()[0];
|
||||
if (!result.limbs()[0])
|
||||
result.sign(false);
|
||||
}
|
||||
else
|
||||
eval_add(result, one);
|
||||
}
|
||||
@@ -429,7 +433,7 @@ BOOST_MP_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<Mi
|
||||
static const limb_type one = 1;
|
||||
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))
|
||||
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);
|
||||
|
||||
@@ -326,7 +326,7 @@ inline void left_shift_byte(Int& result, double_limb_type s)
|
||||
if(rs != ors)
|
||||
pr[rs - 1] = 0u;
|
||||
std::size_t bytes = static_cast<std::size_t>(s / CHAR_BIT);
|
||||
std::size_t len = std::min(ors * sizeof(limb_type), rs * sizeof(limb_type) - bytes);
|
||||
std::size_t len = (std::min)(ors * sizeof(limb_type), rs * sizeof(limb_type) - bytes);
|
||||
if(bytes >= rs * sizeof(limb_type))
|
||||
result = static_cast<limb_type>(0u);
|
||||
else
|
||||
@@ -411,14 +411,14 @@ inline void left_shift_generic(Int& result, double_limb_type s)
|
||||
++i;
|
||||
}
|
||||
}
|
||||
for(; ors > 1 + i; ++i)
|
||||
for(; rs - i >= 2 + offset; ++i)
|
||||
{
|
||||
pr[rs - 1 - i] = pr[ors - 1 - i] << shift;
|
||||
pr[rs - 1 - i] |= pr[ors - 2 - i] >> (Int::limb_bits - shift);
|
||||
pr[rs - 1 - i] = pr[rs - 1 - i - offset] << shift;
|
||||
pr[rs - 1 - i] |= pr[rs - 2 - i - offset] >> (Int::limb_bits - shift);
|
||||
}
|
||||
if(ors >= 1 + i)
|
||||
if(rs - i >= 1 + offset)
|
||||
{
|
||||
pr[rs - 1 - i] = pr[ors - 1 - i] << shift;
|
||||
pr[rs - 1 - i] = pr[rs - 1 - i - offset] << shift;
|
||||
++i;
|
||||
}
|
||||
for(; i < rs; ++i)
|
||||
@@ -435,7 +435,7 @@ inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBit
|
||||
if(!s)
|
||||
return;
|
||||
|
||||
#if defined(BOOST_LITTLE_ENDIAN) && defined(BOOST_MP_USE_LIMB_SHIFT)
|
||||
#if BOOST_ENDIAN_LITTLE_BYTE && defined(BOOST_MP_USE_LIMB_SHIFT)
|
||||
static const limb_type limb_shift_mask = cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits - 1;
|
||||
static const limb_type byte_shift_mask = CHAR_BIT - 1;
|
||||
if((s & limb_shift_mask) == 0)
|
||||
@@ -446,7 +446,7 @@ inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBit
|
||||
{
|
||||
left_shift_byte(result, s);
|
||||
}
|
||||
#elif defined(BOOST_LITTLE_ENDIAN)
|
||||
#elif BOOST_ENDIAN_LITTLE_BYTE
|
||||
static const limb_type byte_shift_mask = CHAR_BIT - 1;
|
||||
if((s & byte_shift_mask) == 0)
|
||||
{
|
||||
@@ -562,14 +562,14 @@ inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBit
|
||||
if(!s)
|
||||
return;
|
||||
|
||||
#if defined(BOOST_LITTLE_ENDIAN) && defined(BOOST_MP_USE_LIMB_SHIFT)
|
||||
#if BOOST_ENDIAN_LITTLE_BYTE && defined(BOOST_MP_USE_LIMB_SHIFT)
|
||||
static const limb_type limb_shift_mask = cpp_int_backend<MinBits1, MaxBits1, signed_magnitude, Checked1, Allocator1>::limb_bits - 1;
|
||||
static const limb_type byte_shift_mask = CHAR_BIT - 1;
|
||||
if((s & limb_shift_mask) == 0)
|
||||
right_shift_limb(result, s);
|
||||
else if((s & byte_shift_mask) == 0)
|
||||
right_shift_byte(result, s);
|
||||
#elif defined(BOOST_LITTLE_ENDIAN)
|
||||
#elif BOOST_ENDIAN_LITTLE_BYTE
|
||||
static const limb_type byte_shift_mask = CHAR_BIT - 1;
|
||||
if((s & byte_shift_mask) == 0)
|
||||
right_shift_byte(result, s);
|
||||
@@ -595,14 +595,14 @@ inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBit
|
||||
if(is_neg)
|
||||
eval_increment(result);
|
||||
|
||||
#if defined(BOOST_LITTLE_ENDIAN) && defined(BOOST_MP_USE_LIMB_SHIFT)
|
||||
#if BOOST_ENDIAN_LITTLE_BYTE && defined(BOOST_MP_USE_LIMB_SHIFT)
|
||||
static const limb_type limb_shift_mask = cpp_int_backend<MinBits1, MaxBits1, signed_magnitude, Checked1, Allocator1>::limb_bits - 1;
|
||||
static const limb_type byte_shift_mask = CHAR_BIT - 1;
|
||||
if((s & limb_shift_mask) == 0)
|
||||
right_shift_limb(result, s);
|
||||
else if((s & byte_shift_mask) == 0)
|
||||
right_shift_byte(result, s);
|
||||
#elif defined(BOOST_LITTLE_ENDIAN)
|
||||
#elif BOOST_ENDIAN_LITTLE_BYTE
|
||||
static const limb_type byte_shift_mask = CHAR_BIT - 1;
|
||||
if((s & byte_shift_mask) == 0)
|
||||
right_shift_byte(result, s);
|
||||
|
||||
@@ -220,7 +220,7 @@ void divide_unsigned_helper(
|
||||
//
|
||||
double_limb_type carry = 0;
|
||||
t.resize(y.size() + shift + 1, y.size() + shift);
|
||||
bool truncated_t = !CppInt1::variable && (t.size() != y.size() + shift + 1);
|
||||
bool truncated_t = (t.size() != y.size() + shift + 1);
|
||||
typename CppInt1::limb_pointer pt = t.limbs();
|
||||
for(unsigned i = 0; i < shift; ++i)
|
||||
pt[i] = 0;
|
||||
|
||||
@@ -61,8 +61,7 @@ namespace boost {
|
||||
// Check for overflow bits:
|
||||
//
|
||||
bit_location = sizeof(local_limb_type) * CHAR_BIT - bit_location;
|
||||
bits >>= bit_location;
|
||||
if(bits)
|
||||
if((bit_location < sizeof(bits)*CHAR_BIT) && (bits >>= bit_location))
|
||||
val.resize(2, 2); // May throw!
|
||||
}
|
||||
}
|
||||
@@ -134,7 +133,7 @@ namespace boost {
|
||||
cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>& result = val.backend();
|
||||
result.resize(static_cast<unsigned>(limb_len), static_cast<unsigned>(limb_len)); // checked types may throw here if they're not large enough to hold the data!
|
||||
result.limbs()[result.size() - 1] = 0u;
|
||||
std::memcpy(result.limbs(), i, std::min(byte_len, result.size() * sizeof(limb_type)));
|
||||
std::memcpy(result.limbs(), i, (std::min)(byte_len, result.size() * sizeof(limb_type)));
|
||||
result.normalize(); // In case data has leading zeros.
|
||||
return val;
|
||||
}
|
||||
@@ -150,7 +149,7 @@ namespace boost {
|
||||
++limb_len;
|
||||
result.limbs()[0] = 0u;
|
||||
result.resize(static_cast<unsigned>(limb_len), static_cast<unsigned>(limb_len)); // checked types may throw here if they're not large enough to hold the data!
|
||||
std::memcpy(result.limbs(), i, std::min(byte_len, result.size() * sizeof(result.limbs()[0])));
|
||||
std::memcpy(result.limbs(), i, (std::min)(byte_len, result.size() * sizeof(result.limbs()[0])));
|
||||
result.normalize(); // In case data has leading zeros.
|
||||
return val;
|
||||
}
|
||||
@@ -170,7 +169,7 @@ namespace boost {
|
||||
import_bits(
|
||||
number<cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates>& val, T* i, T* j, unsigned chunk_size = 0, bool msv_first = true)
|
||||
{
|
||||
#ifdef BOOST_LITTLE_ENDIAN
|
||||
#if BOOST_ENDIAN_LITTLE_BYTE
|
||||
if(((chunk_size % CHAR_BIT) == 0) && !msv_first)
|
||||
return detail::import_bits_fast(val, i, j, chunk_size);
|
||||
#endif
|
||||
@@ -199,8 +198,8 @@ namespace boost {
|
||||
template <class Backend>
|
||||
inline boost::uintmax_t extract_bits(const Backend& val, unsigned location, unsigned count, const mpl::true_&)
|
||||
{
|
||||
boost::uintmax_t result = *val.limbs();
|
||||
boost::uintmax_t mask = count == std::numeric_limits<boost::uintmax_t>::digits ? ~static_cast<boost::uintmax_t>(0) : (static_cast<boost::uintmax_t>(1u) << count) - 1;
|
||||
typename Backend::local_limb_type result = *val.limbs();
|
||||
typename Backend::local_limb_type mask = count >= std::numeric_limits<typename Backend::local_limb_type>::digits ? ~static_cast<typename Backend::local_limb_type>(0) : (static_cast<typename Backend::local_limb_type>(1u) << count) - 1;
|
||||
return (result >> location) & mask;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ inline boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinB
|
||||
{
|
||||
// Bounded and signed.
|
||||
typedef boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> result_type;
|
||||
typedef boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, Allocator>, ExpressionTemplates> ui_type;
|
||||
typedef boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MaxBits, MaxBits, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked>, ExpressionTemplates> ui_type;
|
||||
static const result_type val = -result_type(~ui_type(0));
|
||||
return val;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ inline boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinB
|
||||
{
|
||||
// Bounded and signed.
|
||||
typedef boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> result_type;
|
||||
typedef boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, Allocator>, ExpressionTemplates> ui_type;
|
||||
typedef boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MaxBits, MaxBits, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked>, ExpressionTemplates> ui_type;
|
||||
static const result_type val = ~ui_type(0);
|
||||
return val;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ void check_in_range(const CppInt& val, const mpl::int_<checked>&)
|
||||
typedef typename boost::multiprecision::detail::canonical<R, CppInt>::type cast_type;
|
||||
if(val.sign())
|
||||
{
|
||||
if(boost::is_signed<R>::value == false)
|
||||
BOOST_THROW_EXCEPTION(std::range_error("Attempt to assign a negative value to an unsigned type."));
|
||||
if(val.compare(static_cast<cast_type>((std::numeric_limits<R>::min)())) < 0)
|
||||
BOOST_THROW_EXCEPTION(std::overflow_error("Could not convert to the target type - -value is out of range."));
|
||||
}
|
||||
@@ -59,17 +61,71 @@ inline Integer negate_integer(Integer i, const mpl::false_&) BOOST_NOEXCEPT
|
||||
|
||||
template <class R, unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline typename enable_if_c<is_integral<R>::value && !is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value, void>::type
|
||||
eval_convert_to(R* result, const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& backend) BOOST_MP_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
eval_convert_to(R* result, const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& backend)
|
||||
{
|
||||
typedef mpl::int_<Checked1> checked_type;
|
||||
check_in_range<R>(backend, checked_type());
|
||||
|
||||
*result = static_cast<R>(backend.limbs()[0]);
|
||||
unsigned shift = cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
for(unsigned i = 1; (i < backend.size()) && (shift < static_cast<unsigned>(std::numeric_limits<R>::digits)); ++i)
|
||||
if (std::numeric_limits<R>::digits < cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits)
|
||||
{
|
||||
*result += static_cast<R>(backend.limbs()[i]) << shift;
|
||||
shift += cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
if ((backend.sign() && boost::is_signed<R>::value) && (1 + static_cast<boost::multiprecision::limb_type>((std::numeric_limits<R>::max)()) <= backend.limbs()[0]))
|
||||
{
|
||||
*result = (std::numeric_limits<R>::min)();
|
||||
return;
|
||||
}
|
||||
else if (boost::is_signed<R>::value && !backend.sign() && static_cast<boost::multiprecision::limb_type>((std::numeric_limits<R>::max)()) <= backend.limbs()[0])
|
||||
{
|
||||
*result = (std::numeric_limits<R>::max)();
|
||||
return;
|
||||
}
|
||||
else
|
||||
*result = static_cast<R>(backend.limbs()[0]);
|
||||
}
|
||||
else
|
||||
*result = static_cast<R>(backend.limbs()[0]);
|
||||
unsigned shift = cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
unsigned i = 1;
|
||||
if (std::numeric_limits<R>::digits > cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits)
|
||||
{
|
||||
while ((i < backend.size()) && (shift < static_cast<unsigned>(std::numeric_limits<R>::digits - cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits)))
|
||||
{
|
||||
*result += static_cast<R>(backend.limbs()[i]) << shift;
|
||||
shift += cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
++i;
|
||||
}
|
||||
//
|
||||
// We have one more limb to extract, but may not need all the bits, so treat this as a special case:
|
||||
//
|
||||
if (i < backend.size())
|
||||
{
|
||||
static const limb_type mask = std::numeric_limits<R>::digits - shift == cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits ?
|
||||
~static_cast<limb_type>(0) : (static_cast<limb_type>(1u) << (std::numeric_limits<R>::digits - shift)) - 1;
|
||||
*result += (static_cast<R>(backend.limbs()[i]) & mask) << shift;
|
||||
if ((static_cast<R>(backend.limbs()[i]) & static_cast<limb_type>(~mask)) || (i + 1 < backend.size()))
|
||||
{
|
||||
// Overflow:
|
||||
if (backend.sign())
|
||||
{
|
||||
check_is_negative(boost::is_signed<R>());
|
||||
*result = (std::numeric_limits<R>::min)();
|
||||
}
|
||||
else if(boost::is_signed<R>::value)
|
||||
*result = (std::numeric_limits<R>::max)();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (backend.size() > 1)
|
||||
{
|
||||
// Overflow:
|
||||
if (backend.sign())
|
||||
{
|
||||
check_is_negative(boost::is_signed<R>());
|
||||
*result = (std::numeric_limits<R>::min)();
|
||||
}
|
||||
else if(boost::is_signed<R>::value)
|
||||
*result = (std::numeric_limits<R>::max)();
|
||||
return;
|
||||
}
|
||||
if(backend.sign())
|
||||
{
|
||||
@@ -551,6 +607,7 @@ inline typename enable_if_c<
|
||||
{
|
||||
if(val.isneg())
|
||||
{
|
||||
check_is_negative(mpl::bool_<boost::is_signed<R>::value || (number_category<R>::value == number_kind_floating_point)>());
|
||||
if(static_cast<common_type>(*val.limbs()) > -static_cast<common_type>((std::numeric_limits<R>::min)()))
|
||||
conversion_overflow(typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
*result = (std::numeric_limits<R>::min)();
|
||||
@@ -558,7 +615,7 @@ inline typename enable_if_c<
|
||||
else
|
||||
{
|
||||
conversion_overflow(typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
*result = (std::numeric_limits<R>::max)();
|
||||
*result = boost::is_signed<R>::value ? (std::numeric_limits<R>::max)() : static_cast<R>(*val.limbs());
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -566,7 +623,7 @@ inline typename enable_if_c<
|
||||
*result = static_cast<R>(*val.limbs());
|
||||
if(val.isneg())
|
||||
{
|
||||
check_is_negative(mpl::bool_<is_signed_number<R>::value || (number_category<R>::value == number_kind_floating_point)>());
|
||||
check_is_negative(mpl::bool_<boost::is_signed<R>::value || (number_category<R>::value == number_kind_floating_point)>());
|
||||
*result = negate_integer(*result, mpl::bool_<is_signed_number<R>::value || (number_category<R>::value == number_kind_floating_point)>());
|
||||
}
|
||||
}
|
||||
@@ -584,7 +641,7 @@ inline typename enable_if_c<
|
||||
if(std::numeric_limits<R>::is_specialized && (static_cast<common_type>(*val.limbs()) > static_cast<common_type>((std::numeric_limits<R>::max)())))
|
||||
{
|
||||
conversion_overflow(typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
*result = (std::numeric_limits<R>::max)();
|
||||
*result = boost::is_signed<R>::value ? (std::numeric_limits<R>::max)() : static_cast<R>(*val.limbs());
|
||||
}
|
||||
else
|
||||
*result = static_cast<R>(*val.limbs());
|
||||
|
||||
@@ -48,7 +48,7 @@ inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBit
|
||||
{
|
||||
unsigned i = result.size();
|
||||
result.resize(i + 1, i + 1);
|
||||
if(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::variable || (result.size() > i))
|
||||
if(result.size() > i)
|
||||
result.limbs()[i] = static_cast<limb_type>(carry);
|
||||
}
|
||||
result.sign(a.sign());
|
||||
@@ -64,10 +64,10 @@ inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBit
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline void resize_for_carry(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& /*result*/, unsigned /*required*/){}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline void resize_for_carry(cpp_int_backend<MinBits1, MaxBits1, SignType1, checked, void>& result, unsigned required)
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, class Allocator1>
|
||||
inline void resize_for_carry(cpp_int_backend<MinBits1, MaxBits1, SignType1, checked, Allocator1>& result, unsigned required)
|
||||
{
|
||||
if(result.size() != required)
|
||||
if(result.size() < required)
|
||||
result.resize(required, required);
|
||||
}
|
||||
|
||||
@@ -136,7 +136,8 @@ inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBit
|
||||
for(unsigned i = 0; i < as; ++i)
|
||||
{
|
||||
unsigned inner_limit = cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::variable ? bs : (std::min)(result.size() - i, bs);
|
||||
for(unsigned j = 0; j < inner_limit; ++j)
|
||||
unsigned j;
|
||||
for(j = 0; j < inner_limit; ++j)
|
||||
{
|
||||
BOOST_ASSERT(i+j < result.size());
|
||||
#if (!defined(__GLIBCXX__) && !defined(__GLIBCPP__)) || !BOOST_WORKAROUND(BOOST_GCC_VERSION, <= 50100)
|
||||
@@ -156,9 +157,16 @@ inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBit
|
||||
carry >>= cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
BOOST_ASSERT(carry <= (cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::max_limb_value));
|
||||
}
|
||||
resize_for_carry(result, as + bs); // May throw if checking is enabled
|
||||
if(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::variable || (i + bs < result.size()))
|
||||
pr[i + bs] = static_cast<limb_type>(carry);
|
||||
if(carry)
|
||||
{
|
||||
resize_for_carry(result, i + j + 1); // May throw if checking is enabled
|
||||
if(i + j < result.size())
|
||||
#ifdef __MSVC_RUNTIME_CHECKS
|
||||
pr[i + j] = static_cast<limb_type>(carry & ~static_cast<limb_type>(0));
|
||||
#else
|
||||
pr[i + j] = static_cast<limb_type>(carry);
|
||||
#endif
|
||||
}
|
||||
carry = 0;
|
||||
}
|
||||
result.normalize();
|
||||
@@ -197,7 +205,7 @@ BOOST_MP_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<Mi
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(BOOST_LITTLE_ENDIAN) && !defined(BOOST_MP_TEST_NO_LE)
|
||||
#if BOOST_ENDIAN_LITTLE_BYTE && !defined(BOOST_MP_TEST_NO_LE)
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> t(val);
|
||||
#else
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> t;
|
||||
@@ -258,7 +266,7 @@ inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBit
|
||||
result.negate();
|
||||
return;
|
||||
}
|
||||
#if defined(BOOST_LITTLE_ENDIAN) && !defined(BOOST_MP_TEST_NO_LE)
|
||||
#if BOOST_ENDIAN_LITTLE_BYTE && !defined(BOOST_MP_TEST_NO_LE)
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> t(val);
|
||||
#else
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> t;
|
||||
|
||||
@@ -44,11 +44,12 @@ void do_serialize(Archive& ar, Int& val, mpl::false_ const&, mpl::false_ const&,
|
||||
// Non-trivial.
|
||||
// Non binary.
|
||||
|
||||
using boost::serialization::make_nvp;
|
||||
bool s;
|
||||
ar & s;
|
||||
ar & make_nvp("sign", s);
|
||||
std::size_t limb_count;
|
||||
std::size_t byte_count;
|
||||
ar & byte_count;
|
||||
ar & make_nvp("byte-count", byte_count);
|
||||
limb_count = byte_count / sizeof(limb_type) + ((byte_count % sizeof(limb_type)) ? 1 : 0);
|
||||
val.resize(limb_count, limb_count);
|
||||
limb_type* pl = val.limbs();
|
||||
@@ -58,7 +59,7 @@ void do_serialize(Archive& ar, Int& val, mpl::false_ const&, mpl::false_ const&,
|
||||
for(std::size_t j = 0; (j < sizeof(limb_type)) && byte_count; ++j)
|
||||
{
|
||||
unsigned char byte;
|
||||
ar & byte;
|
||||
ar & make_nvp("byte", byte);
|
||||
pl[i] |= static_cast<limb_type>(byte) << (j * CHAR_BIT);
|
||||
--byte_count;
|
||||
}
|
||||
@@ -74,12 +75,13 @@ void do_serialize(Archive& ar, Int& val, mpl::true_ const&, mpl::false_ const&,
|
||||
// Non-trivial.
|
||||
// Non binary.
|
||||
|
||||
using boost::serialization::make_nvp;
|
||||
bool s = val.sign();
|
||||
ar & s;
|
||||
ar & make_nvp("sign", s);
|
||||
limb_type* pl = val.limbs();
|
||||
std::size_t limb_count = val.size();
|
||||
std::size_t byte_count = limb_count * sizeof(limb_type);
|
||||
ar & byte_count;
|
||||
ar & make_nvp("byte-count", byte_count);
|
||||
|
||||
for(std::size_t i = 0; i < limb_count; ++i)
|
||||
{
|
||||
@@ -87,7 +89,7 @@ void do_serialize(Archive& ar, Int& val, mpl::true_ const&, mpl::false_ const&,
|
||||
for(std::size_t j = 0; j < sizeof(limb_type); ++j)
|
||||
{
|
||||
unsigned char byte = static_cast<unsigned char>((l >> (j * CHAR_BIT)) & ((1u << CHAR_BIT) - 1));
|
||||
ar & byte;
|
||||
ar & make_nvp("byte", byte);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,15 +99,16 @@ void do_serialize(Archive& ar, Int& val, mpl::false_ const&, mpl::true_ const&,
|
||||
// Load.
|
||||
// Trivial.
|
||||
// Non binary.
|
||||
using boost::serialization::make_nvp;
|
||||
bool s;
|
||||
typename Int::local_limb_type l = 0;
|
||||
ar & s;
|
||||
ar & make_nvp("sign", s);
|
||||
std::size_t byte_count;
|
||||
ar & byte_count;
|
||||
ar & make_nvp("byte-count", byte_count);
|
||||
for(std::size_t i = 0; i < byte_count; ++i)
|
||||
{
|
||||
unsigned char b;
|
||||
ar & b;
|
||||
ar & make_nvp("byte", b);
|
||||
l |= static_cast<typename Int::local_limb_type>(b) << (i * CHAR_BIT);
|
||||
}
|
||||
*val.limbs() = l;
|
||||
@@ -118,15 +121,16 @@ void do_serialize(Archive& ar, Int& val, mpl::true_ const&, mpl::true_ const&, m
|
||||
// Store.
|
||||
// Trivial.
|
||||
// Non binary.
|
||||
using boost::serialization::make_nvp;
|
||||
bool s = val.sign();
|
||||
typename Int::local_limb_type l = *val.limbs();
|
||||
ar & s;
|
||||
ar & make_nvp("sign", s);
|
||||
std::size_t limb_count = sizeof(l);
|
||||
ar & limb_count;
|
||||
ar & make_nvp("byte-count", limb_count);
|
||||
for(std::size_t i = 0; i < limb_count; ++i)
|
||||
{
|
||||
unsigned char b = static_cast<unsigned char>(static_cast<typename Int::local_limb_type>(l >> (i * CHAR_BIT)) & static_cast<typename Int::local_limb_type>((1u << CHAR_BIT) - 1));
|
||||
ar & b;
|
||||
ar & make_nvp("byte", b);
|
||||
}
|
||||
}
|
||||
template <class Archive, class Int>
|
||||
|
||||
Reference in New Issue
Block a user