From c72c47902353ef005fec4af5f1095a9c72219c03 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Wed, 15 Dec 2021 15:18:47 +0000 Subject: [PATCH] Change all bit counts to use size_t/ptrdiff_t. Fixes https://github.com/boostorg/multiprecision/issues/362 --- doc/tutorial_cpp_int.qbk | 6 +- doc/tutorial_import_export.qbk | 8 +- .../boost/multiprecision/cpp_bin_float.hpp | 52 ++-- .../boost/multiprecision/cpp_bin_float/io.hpp | 12 +- .../cpp_bin_float/transcendental.hpp | 4 +- include/boost/multiprecision/cpp_int.hpp | 272 +++++++++--------- include/boost/multiprecision/cpp_int/add.hpp | 42 +-- .../multiprecision/cpp_int/add_unsigned.hpp | 22 +- .../boost/multiprecision/cpp_int/bitwise.hpp | 134 ++++----- .../multiprecision/cpp_int/comparison.hpp | 64 ++--- .../multiprecision/cpp_int/cpp_int_config.hpp | 14 +- .../boost/multiprecision/cpp_int/divide.hpp | 54 ++-- .../multiprecision/cpp_int/import_export.hpp | 60 ++-- .../boost/multiprecision/cpp_int/limits.hpp | 72 ++--- .../boost/multiprecision/cpp_int/literals.hpp | 8 +- include/boost/multiprecision/cpp_int/misc.hpp | 188 ++++++------ .../boost/multiprecision/cpp_int/multiply.hpp | 126 ++++---- .../multiprecision/cpp_int/serialize.hpp | 2 +- .../boost/multiprecision/debug_adaptor.hpp | 14 +- .../boost/multiprecision/detail/bitscan.hpp | 56 ++-- .../multiprecision/detail/default_ops.hpp | 22 +- .../detail/float_string_cvt.hpp | 2 +- .../detail/generic_interconvert.hpp | 10 +- .../multiprecision/detail/integer_ops.hpp | 24 +- .../boost/multiprecision/detail/precision.hpp | 2 +- include/boost/multiprecision/gmp.hpp | 12 +- include/boost/multiprecision/integer.hpp | 14 +- .../boost/multiprecision/logged_adaptor.hpp | 20 +- include/boost/multiprecision/miller_rabin.hpp | 30 +- .../boost/multiprecision/rational_adaptor.hpp | 4 +- include/boost/multiprecision/tommath.hpp | 4 +- test/constexpr_test_cpp_int_5.cpp | 16 +- test/standalone_test_arithmetic_cpp_int.cpp | 4 +- ...tandalone_test_arithmetic_cpp_rational.cpp | 4 +- test/standalone_test_arithmetic_int512.cpp | 4 +- test/test_arithmetic_cpp_int_1.cpp | 4 +- test/test_arithmetic_cpp_int_10.cpp | 4 +- test/test_arithmetic_cpp_int_11.cpp | 6 +- test/test_arithmetic_cpp_int_12.cpp | 6 +- test/test_arithmetic_cpp_int_13.cpp | 6 +- test/test_arithmetic_cpp_int_14.cpp | 4 +- test/test_arithmetic_cpp_int_15.cpp | 6 +- test/test_arithmetic_cpp_int_16.cpp | 6 +- test/test_arithmetic_cpp_int_17.cpp | 4 +- test/test_arithmetic_cpp_int_18.cpp | 6 +- test/test_arithmetic_cpp_int_19.cpp | 2 +- test/test_arithmetic_cpp_int_2.cpp | 4 +- test/test_arithmetic_cpp_int_20.cpp | 2 +- test/test_arithmetic_cpp_int_21.cpp | 2 +- test/test_arithmetic_cpp_int_3.cpp | 4 +- test/test_arithmetic_cpp_int_4.cpp | 4 +- test/test_arithmetic_cpp_int_5.cpp | 6 +- test/test_arithmetic_cpp_int_6.cpp | 4 +- test/test_arithmetic_cpp_int_7.cpp | 4 +- test/test_arithmetic_cpp_int_8.cpp | 4 +- test/test_arithmetic_cpp_int_9.cpp | 4 +- test/test_arithmetic_cpp_int_br.cpp | 4 +- test/test_arithmetic_cpp_int_dbg_adptr.cpp | 2 +- test/test_arithmetic_cpp_int_logged_adptr.cpp | 2 +- test/test_cpp_int.cpp | 2 +- test/test_cpp_int_import_export.cpp | 2 +- test/test_cpp_int_karatsuba.cpp | 2 +- test/test_gcd.cpp | 8 +- test/test_int_io.cpp | 2 +- 64 files changed, 749 insertions(+), 749 deletions(-) diff --git a/doc/tutorial_cpp_int.qbk b/doc/tutorial_cpp_int.qbk index 66a13024..d11dbf21 100644 --- a/doc/tutorial_cpp_int.qbk +++ b/doc/tutorial_cpp_int.qbk @@ -19,8 +19,8 @@ enum cpp_integer_type { signed_magnitude, unsigned_magnitude }; enum cpp_int_check_type { checked, unchecked }; - template > @@ -28,7 +28,7 @@ // // Expression templates default to et_off if there is no allocator: // - template + template struct expression_template_default > { static const expression_template_option value = et_off; }; diff --git a/doc/tutorial_import_export.qbk b/doc/tutorial_import_export.qbk index 01764a92..94bfdb47 100644 --- a/doc/tutorial_import_export.qbk +++ b/doc/tutorial_import_export.qbk @@ -12,7 +12,7 @@ Any integer number type that uses `cpp_int_backend` as its implementation layer can import or export its bits via two non-member functions: - template OutputIterator export_bits( const number, ExpressionTemplates>& val, @@ -20,7 +20,7 @@ Any integer number type that uses `cpp_int_backend` as its implementation layer unsigned chunk_size, bool msv_first = true); - template number, ExpressionTemplates>& import_bits( @@ -34,7 +34,7 @@ These functions are designed for data-interchange with other storage formats, an by extension they can be used for floating-point numbers based on that backend as well (see example below). Parameters and use are as follows: - template OutputIterator export_bits( const number, ExpressionTemplates>& val, @@ -55,7 +55,7 @@ has to be specified manually. It may also result in compiler warnings about the [@http://www.boost.org/doc/libs/release/libs/endian/doc/index.html Boost.Endian] to create a custom OutputIterator that reverses the byte order of each chunk prior to actually storing the result.] - template number, ExpressionTemplates>& import_bits( diff --git a/include/boost/multiprecision/cpp_bin_float.hpp b/include/boost/multiprecision/cpp_bin_float.hpp index 5efe35c1..8c8b57f4 100644 --- a/include/boost/multiprecision/cpp_bin_float.hpp +++ b/include/boost/multiprecision/cpp_bin_float.hpp @@ -53,13 +53,13 @@ inline typename std::enable_if::va template inline typename std::enable_if< !boost::multiprecision::detail::is_unsigned::value, bool>::type is_negative(S s) { return s < 0; } -template ::value == number_kind_floating_point> +template ::value == number_kind_floating_point> struct is_cpp_bin_float_implicitly_constructible_from_type { static constexpr const bool value = false; }; -template +template struct is_cpp_bin_float_implicitly_constructible_from_type { static constexpr const bool value = (std::numeric_limits::digits <= (int)bit_count) && (std::numeric_limits::radix == 2) && std::numeric_limits::is_specialized @@ -69,13 +69,13 @@ struct is_cpp_bin_float_implicitly_constructible_from_type::value || is_number::value); }; -template ::value == number_kind_floating_point> +template ::value == number_kind_floating_point> struct is_cpp_bin_float_explicitly_constructible_from_type { static constexpr const bool value = false; }; -template +template struct is_cpp_bin_float_explicitly_constructible_from_type { static constexpr const bool value = (std::numeric_limits::digits > (int)bit_count) && (std::numeric_limits::radix == 2) && std::numeric_limits::is_specialized @@ -334,7 +334,7 @@ class cpp_bin_float m_sign = false; m_exponent = 0; - constexpr const int bits = sizeof(int) * CHAR_BIT - 1; + constexpr const std::ptrdiff_t bits = sizeof(int) * CHAR_BIT - 1; int e; f = frexpq(f, &e); while (f) @@ -394,7 +394,7 @@ class cpp_bin_float m_sign = false; m_exponent = 0; - constexpr const int bits = sizeof(int) * CHAR_BIT - 1; + constexpr const std::ptrdiff_t bits = sizeof(int) * CHAR_BIT - 1; int e; f = frexp(f, &e); while (f) @@ -462,7 +462,7 @@ class cpp_bin_float m_sign = false; m_exponent = 0; - constexpr const int bits = sizeof(int) * CHAR_BIT - 1; + constexpr const std::ptrdiff_t bits = sizeof(int) * CHAR_BIT - 1; int e; eval_frexp(f, f, &e); while (eval_get_sign(f) != 0) @@ -513,7 +513,7 @@ class cpp_bin_float ui_type fi = static_cast(boost::multiprecision::detail::unsigned_abs(i)); using ar_type = typename boost::multiprecision::detail::canonical::type; m_data = static_cast(fi); - unsigned shift = msb(fi); + std::size_t shift = msb(fi); if (shift >= bit_count) { m_exponent = static_cast(shift); @@ -615,7 +615,7 @@ class cpp_bin_float #endif template -inline void copy_and_round(cpp_bin_float& res, Int& arg, int bits_to_keep = cpp_bin_float::bit_count) +inline void copy_and_round(cpp_bin_float& res, Int& arg, std::ptrdiff_t bits_to_keep = cpp_bin_float::bit_count) { // Precondition: exponent of res must have been set before this function is called // as we may need to adjust it based on how many bits_to_keep in arg are set. @@ -635,8 +635,8 @@ inline void copy_and_round(cpp_bin_float(0u); return; } - int msb = eval_msb(arg); - if (static_cast(bits_to_keep) > msb + 1) + std::ptrdiff_t msb = eval_msb(arg); + if (static_cast(bits_to_keep) > msb + 1) { // Must have had cancellation in subtraction, // or be converting from a narrower type, so shift left: @@ -644,13 +644,13 @@ inline void copy_and_round(cpp_bin_float(bits_to_keep - msb - 1); } - else if (static_cast(bits_to_keep) < msb + 1) + else if (static_cast(bits_to_keep) < msb + 1) { // We have more bits_to_keep than we need, so round as required, // first get the rounding bit: bool roundup = eval_bit_test(arg, msb - bits_to_keep); // Then check for a tie: - if (roundup && (msb - bits_to_keep == (int)eval_lsb(arg))) + if (roundup && (msb - bits_to_keep == (std::ptrdiff_t )eval_lsb(arg))) { // Ties round towards even: if (!eval_bit_test(arg, msb - bits_to_keep + 1)) @@ -699,7 +699,7 @@ inline void copy_and_round(cpp_bin_float::bit_count - 1)); + BOOST_MP_ASSERT(((std::ptrdiff_t )eval_msb(res.bits()) == cpp_bin_float::bit_count - 1)); if (res.exponent() > cpp_bin_float::max_exponent) { @@ -774,7 +774,7 @@ inline void do_eval_add(cpp_bin_float (int)cpp_bin_float::bit_count + b.exponent()) + if (a.exponent() > (std::ptrdiff_t )cpp_bin_float::bit_count + b.exponent()) { res.exponent() = a.exponent(); } @@ -847,14 +847,14 @@ inline void do_eval_subtract(BinFloat1& res, const BinFloat2& a, const BinFloat3 if ((a.exponent() > b.exponent()) || ((a.exponent() == b.exponent()) && a.bits().compare(b.bits()) >= 0)) { dt = a.bits(); - if (a.exponent() <= (int)BinFloat1::bit_count + b.exponent()) + if (a.exponent() <= (std::ptrdiff_t )BinFloat1::bit_count + b.exponent()) { typename BinFloat1::exponent_type e_diff = a.exponent() - b.exponent(); eval_left_shift(dt, e_diff); res.exponent() = a.exponent() - e_diff; eval_subtract(dt, b.bits()); } - else if (a.exponent() == (int)BinFloat1::bit_count + b.exponent() + 1) + else if (a.exponent() == (std::ptrdiff_t )BinFloat1::bit_count + b.exponent() + 1) { if ((eval_lsb(a.bits()) == BinFloat1::bit_count - 1) && (eval_lsb(b.bits()) != BinFloat1::bit_count - 1)) @@ -872,14 +872,14 @@ inline void do_eval_subtract(BinFloat1& res, const BinFloat2& a, const BinFloat3 else { dt = b.bits(); - if (b.exponent() <= (int)BinFloat1::bit_count + a.exponent()) + if (b.exponent() <= (std::ptrdiff_t )BinFloat1::bit_count + a.exponent()) { typename BinFloat1::exponent_type e_diff = a.exponent() - b.exponent(); eval_left_shift(dt, -e_diff); res.exponent() = b.exponent() + e_diff; eval_subtract(dt, a.bits()); } - else if (b.exponent() == (int)BinFloat1::bit_count + a.exponent() + 1) + else if (b.exponent() == (std::ptrdiff_t )BinFloat1::bit_count + a.exponent() + 1) { if ((eval_lsb(a.bits()) != BinFloat1::bit_count - 1) && eval_lsb(b.bits())) @@ -1339,7 +1339,7 @@ inline typename std::enable_if::va // // We can set the exponent and sign of the result up front: // - int gb = msb(v); + std::ptrdiff_t gb = msb(v); res.exponent() = u.exponent() - static_cast(gb) - static_cast(1); res.sign() = u.sign(); // @@ -1595,13 +1595,13 @@ inline typename std::enable_if::value>::type eval_ cpp_bin_float::digits, digit_base_2, Allocator, Exponent, MinE, MaxE> arg; typename cpp_bin_float::rep_type bits(original_arg.bits()); arg.exponent() = original_arg.exponent(); - copy_and_round(arg, bits, (int)digits_to_round_to); + copy_and_round(arg, bits, (std::ptrdiff_t )digits_to_round_to); common_exp_type e = arg.exponent(); e -= cpp_bin_float::bit_count - 1; - constexpr const unsigned limbs_needed = std::numeric_limits::digits / (sizeof(*arg.bits().limbs()) * CHAR_BIT) + (std::numeric_limits::digits % (sizeof(*arg.bits().limbs()) * CHAR_BIT) ? 1 : 0); - unsigned first_limb_needed = arg.bits().size() - limbs_needed; + constexpr const std::size_t limbs_needed = std::numeric_limits::digits / (sizeof(*arg.bits().limbs()) * CHAR_BIT) + (std::numeric_limits::digits % (sizeof(*arg.bits().limbs()) * CHAR_BIT) ? 1 : 0); + std::size_t first_limb_needed = arg.bits().size() - limbs_needed; *res = 0; - e += first_limb_needed * sizeof(*arg.bits().limbs()) * CHAR_BIT; + e += static_cast(first_limb_needed * sizeof(*arg.bits().limbs()) * CHAR_BIT); while (first_limb_needed < arg.bits().size()) { *res += std::ldexp(static_cast(arg.bits().limbs()[first_limb_needed]), static_cast(e)); @@ -1825,7 +1825,7 @@ inline void eval_floor(cpp_bin_float::bit_count - 1 - shift) + if ((std::ptrdiff_t)eval_msb(res.bits()) != cpp_bin_float::bit_count - 1 - shift) { // Must have extended result by one bit in the increment: --shift; @@ -1870,7 +1870,7 @@ inline void eval_ceil(cpp_bin_float::bit_count - 1 - shift) + if ((std::ptrdiff_t)eval_msb(res.bits()) != cpp_bin_float::bit_count - 1 - shift) { // Must have extended result by one bit in the increment: --shift; diff --git a/include/boost/multiprecision/cpp_bin_float/io.hpp b/include/boost/multiprecision/cpp_bin_float/io.hpp index e93f5a70..4480cbe7 100644 --- a/include/boost/multiprecision/cpp_bin_float/io.hpp +++ b/include/boost/multiprecision/cpp_bin_float/io.hpp @@ -271,7 +271,7 @@ cpp_bin_float& cpp_bin_float return *this; } - constexpr const unsigned limb_bits = sizeof(limb_type) * CHAR_BIT; + constexpr const std::size_t limb_bits = sizeof(limb_type) * CHAR_BIT; // // Set our working precision - this is heuristic based, we want // a value as small as possible > cpp_bin_float::bit_count to avoid large computations @@ -306,7 +306,7 @@ cpp_bin_float& cpp_bin_float else t = n; final_exponent = (std::int64_t)cpp_bin_float::bit_count - 1 + decimal_exp + calc_exp; - int rshift = msb(t) - cpp_bin_float::bit_count + 1; + std::ptrdiff_t rshift = msb(t) - cpp_bin_float::bit_count + 1; if (rshift > 0) { final_exponent += rshift; @@ -362,7 +362,7 @@ cpp_bin_float& cpp_bin_float { cpp_int d; calc_exp = boost::multiprecision::cpp_bf_io_detail::restricted_pow(d, cpp_int(5), -decimal_exp, max_bits, error); - int shift = (int)cpp_bin_float::bit_count - msb(n) + msb(d); + std::ptrdiff_t shift = (int)cpp_bin_float::bit_count - msb(n) + msb(d); final_exponent = cpp_bin_float::bit_count - 1 + decimal_exp - calc_exp; if (shift > 0) { @@ -371,7 +371,7 @@ cpp_bin_float& cpp_bin_float } cpp_int q, r; divide_qr(n, d, q, r); - int gb = msb(q); + std::ptrdiff_t gb = msb(q); BOOST_MP_ASSERT((gb >= static_cast(cpp_bin_float::bit_count) - 1)); // // Check for rounding conditions we have to @@ -387,7 +387,7 @@ cpp_bin_float& cpp_bin_float { // Too many bits in q and the bits in q indicate a tie, but we can break that using r, // note that the radius of error in r is error/2 * q: - int lshift = gb - (int)cpp_bin_float::bit_count + 1; + std::ptrdiff_t lshift = gb - (int)cpp_bin_float::bit_count + 1; q >>= lshift; final_exponent += static_cast(lshift); BOOST_MP_ASSERT((msb(q) >= cpp_bin_float::bit_count - 1)); @@ -514,7 +514,7 @@ std::string cpp_bin_float::s shift -= power10; cpp_int i; int roundup = 0; // 0=no rounding, 1=tie, 2=up - constexpr const unsigned limb_bits = sizeof(limb_type) * CHAR_BIT; + constexpr const std::size_t limb_bits = sizeof(limb_type) * CHAR_BIT; // // Set our working precision - this is heuristic based, we want // a value as small as possible > cpp_bin_float::bit_count to avoid large computations diff --git a/include/boost/multiprecision/cpp_bin_float/transcendental.hpp b/include/boost/multiprecision/cpp_bin_float/transcendental.hpp index 09dcecd2..d5319539 100644 --- a/include/boost/multiprecision/cpp_bin_float/transcendental.hpp +++ b/include/boost/multiprecision/cpp_bin_float/transcendental.hpp @@ -13,7 +13,7 @@ namespace boost { namespace multiprecision { namespace backends { template void eval_exp_taylor(cpp_bin_float& res, const cpp_bin_float& arg) { - constexpr const int bits = cpp_bin_float::bit_count; + constexpr const std::ptrdiff_t bits = cpp_bin_float::bit_count; // // Taylor series for small argument, note returns exp(x) - 1: // @@ -22,7 +22,7 @@ void eval_exp_taylor(cpp_bin_float >::type> +template >::type> struct cpp_int_backend; } // namespace backends namespace detail { -template +template struct is_byte_container > : public std::false_type {}; @@ -52,14 +52,14 @@ struct is_byte_container + template struct static_unsigned_max { - static constexpr const unsigned value = (Value1 > Value2) ? Value1 : Value2; + static constexpr const std::size_t value = (Value1 > Value2) ? Value1 : Value2; }; } // Namespace detail -template +template struct cpp_int_base; // // Traits class determines the maximum and minimum precision values: @@ -67,20 +67,20 @@ struct cpp_int_base; template struct max_precision; -template +template struct max_precision > { - static constexpr const unsigned value = std::is_void::value ? detail::static_unsigned_max::value + static constexpr const std::size_t value = std::is_void::value ? detail::static_unsigned_max::value : (((MaxBits >= MinBits) && MaxBits) ? MaxBits : UINT_MAX); }; template struct min_precision; -template +template struct min_precision > { - static constexpr const unsigned value = (std::is_void::value ? detail::static_unsigned_max::value : MinBits); + static constexpr const std::size_t value = (std::is_void::value ? detail::static_unsigned_max::value : MinBits); }; // // Traits class determines whether the number of bits precision requested could fit in a native type, @@ -92,14 +92,14 @@ struct is_trivial_cpp_int static constexpr const bool value = false; }; -template +template struct is_trivial_cpp_int > { using self = cpp_int_backend; static constexpr const bool value = std::is_void::value && (max_precision::value <= (sizeof(double_limb_type) * CHAR_BIT) - (SignType == signed_packed ? 1 : 0)); }; -template +template struct is_trivial_cpp_int > { static constexpr const bool value = true; @@ -109,7 +109,7 @@ struct is_trivial_cpp_int +template struct is_unsigned_number > : public std::integral_constant {}; @@ -123,7 +123,7 @@ namespace backends { template struct is_implicit_cpp_int_conversion; -template +template struct is_implicit_cpp_int_conversion, cpp_int_backend > { using t1 = cpp_int_backend ; @@ -138,7 +138,7 @@ struct is_implicit_cpp_int_conversion struct is_non_throwing_cpp_int : public std::integral_constant {}; -template +template struct is_non_throwing_cpp_int > : public std::integral_constant {}; @@ -147,19 +147,19 @@ struct is_non_throwing_cpp_int struct is_fixed_precision; -template +template struct is_fixed_precision > : public std::integral_constant >::value != UINT_MAX> {}; namespace detail { -inline BOOST_MP_CXX14_CONSTEXPR void verify_new_size(unsigned new_size, unsigned min_size, const std::integral_constant&) +inline BOOST_MP_CXX14_CONSTEXPR void verify_new_size(std::size_t new_size, std::size_t min_size, const std::integral_constant&) { if (new_size < min_size) BOOST_MP_THROW_EXCEPTION(std::overflow_error("Unable to allocate sufficient storage for the value of the result: value overflows the maximum allowable magnitude.")); } -inline BOOST_MP_CXX14_CONSTEXPR void verify_new_size(unsigned /*new_size*/, unsigned /*min_size*/, const std::integral_constant&) {} +inline BOOST_MP_CXX14_CONSTEXPR void verify_new_size(std::size_t /*new_size*/, std::size_t /*min_size*/, const std::integral_constant&) {} template inline BOOST_MP_CXX14_CONSTEXPR void verify_limb_mask(bool b, U limb, U mask, const std::integral_constant&) @@ -177,11 +177,11 @@ inline BOOST_MP_CXX14_CONSTEXPR void verify_limb_mask(bool /*b*/, U /*limb*/, U // Now define the various data layouts that are possible as partial specializations of the base class, // starting with the default arbitrary precision signed integer type: // -template +template struct cpp_int_base : private boost::multiprecision::detail::empty_value::type> { - template + template friend struct cpp_int_base; using allocator_type = typename detail::rebind::type; @@ -199,15 +199,15 @@ struct cpp_int_base(0u); static constexpr limb_type sign_bit_mask = static_cast(1u) << (limb_bits - 1); - static constexpr unsigned internal_limb_count = + static constexpr std::size_t internal_limb_count = MinBits ? (MinBits / limb_bits + ((MinBits % limb_bits) ? 1 : 0)) : (sizeof(limb_data) / sizeof(limb_type)) > 1 ? (sizeof(limb_data) / sizeof(limb_type)) : 2; @@ -228,10 +228,10 @@ private: constexpr data_type(signed_double_limb_type i) noexcept : double_first(i < 0 ? static_cast(boost::multiprecision::detail::unsigned_abs(i)) : i) {} #endif #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) && !(defined(BOOST_MSVC) && (BOOST_MSVC < 1900)) - constexpr data_type(limb_type* limbs, unsigned len) noexcept : ld{ len, limbs } + constexpr data_type(limb_type* limbs, std::size_t len) noexcept : ld{ len, limbs } {} #else - constexpr data_type(limb_type* limbs, unsigned len) noexcept + constexpr data_type(limb_type* limbs, std::size_t len) noexcept { ld.capacity = len; ld.data = limbs; @@ -240,7 +240,7 @@ private: }; data_type m_data; - unsigned m_limbs; + std::size_t m_limbs; bool m_sign, m_internal, m_alias; public: @@ -281,42 +281,42 @@ private: { private: limb_type* data; - unsigned capacity; - unsigned allocated; + std::size_t capacity; + std::size_t allocated; bool is_alias; allocator_type& allocator() noexcept { return boost::multiprecision::detail::empty_value::get(); } public: - scoped_shared_storage(const allocator_type& a, unsigned len) + scoped_shared_storage(const allocator_type& a, std::size_t len) : boost::multiprecision::detail::empty_value(boost::multiprecision::detail::empty_init_t(), a), capacity(len), allocated(0), is_alias(false) { data = allocator().allocate(len); } - scoped_shared_storage(const cpp_int_base& i, unsigned len) + scoped_shared_storage(const cpp_int_base& i, std::size_t len) : boost::multiprecision::detail::empty_value(boost::multiprecision::detail::empty_init_t(), i.allocator()), capacity(len), allocated(0), is_alias(false) { data = allocator().allocate(len); } - scoped_shared_storage(limb_type* limbs, unsigned n) : data(limbs), capacity(n), allocated(0), is_alias(true) {} + scoped_shared_storage(limb_type* limbs, std::size_t n) : data(limbs), capacity(n), allocated(0), is_alias(true) {} ~scoped_shared_storage() { if(!is_alias) allocator().deallocate(data, capacity); } - limb_type* allocate(unsigned n) noexcept + limb_type* allocate(std::size_t n) noexcept { limb_type* result = data + allocated; allocated += n; BOOST_MP_ASSERT(allocated <= capacity); return result; } - void deallocate(unsigned n) + void deallocate(std::size_t n) { BOOST_MP_ASSERT(n <= allocated); allocated -= n; } }; - explicit constexpr cpp_int_base(limb_type* data, unsigned offset, unsigned len) noexcept + explicit constexpr cpp_int_base(limb_type* data, std::size_t offset, std::size_t len) noexcept : m_data(data + offset, len), m_limbs(len), m_sign(false), @@ -325,13 +325,13 @@ private: // This next constructor is for constructing const objects from const limb_type*'s only. // Unfortunately we appear to have no way to assert that within the language, and the const_cast // is a side effect of that :( - explicit constexpr cpp_int_base(const limb_type* data, unsigned offset, unsigned len) noexcept + explicit constexpr cpp_int_base(const limb_type* data, std::size_t offset, std::size_t len) noexcept : m_data(const_cast(data) + offset, len), m_limbs(len), m_sign(false), m_internal(false), m_alias(true) {} - explicit cpp_int_base(scoped_shared_storage& data, unsigned len) noexcept + explicit cpp_int_base(scoped_shared_storage& data, std::size_t len) noexcept : m_data(data.allocate(len), len), m_limbs(len), m_sign(false), @@ -342,10 +342,10 @@ private: // BOOST_MP_FORCEINLINE allocator_type& allocator() noexcept { return base_type::get(); } BOOST_MP_FORCEINLINE const allocator_type& allocator() const noexcept { return base_type::get(); } - BOOST_MP_FORCEINLINE unsigned size() const noexcept { return m_limbs; } + BOOST_MP_FORCEINLINE std::size_t size() const noexcept { return m_limbs; } BOOST_MP_FORCEINLINE limb_pointer limbs() noexcept { return m_internal ? m_data.la : m_data.ld.data; } BOOST_MP_FORCEINLINE const_limb_pointer limbs() const noexcept { return m_internal ? m_data.la : m_data.ld.data; } - BOOST_MP_FORCEINLINE unsigned capacity() const noexcept { return m_internal ? internal_limb_count : m_data.ld.capacity; } + BOOST_MP_FORCEINLINE std::size_t capacity() const noexcept { return m_internal ? internal_limb_count : m_data.ld.capacity; } BOOST_MP_FORCEINLINE bool sign() const noexcept { return m_sign; } void sign(bool b) noexcept { @@ -357,15 +357,15 @@ private: m_sign = false; } } - void resize(unsigned new_size, unsigned min_size) + void resize(std::size_t new_size, std::size_t min_size) { - constexpr const unsigned max_limbs = MaxBits / (CHAR_BIT * sizeof(limb_type)) + ((MaxBits % (CHAR_BIT * sizeof(limb_type))) ? 1 : 0); + constexpr const std::size_t max_limbs = MaxBits / (CHAR_BIT * sizeof(limb_type)) + ((MaxBits % (CHAR_BIT * sizeof(limb_type))) ? 1 : 0); // We never resize beyond MaxSize: if (new_size > max_limbs) new_size = max_limbs; detail::verify_new_size(new_size, min_size, checked_type()); // See if we have enough capacity already: - unsigned cap = capacity(); + std::size_t cap = capacity(); if (new_size > cap) { // We must not be an alias, memory allocation here defeats the whole point of aliasing: @@ -442,7 +442,7 @@ private: } return *this; } - template + template cpp_int_base& operator=(cpp_int_base&& o) noexcept { if(o.m_internal) @@ -509,16 +509,16 @@ private: void check_in_range(const A&) noexcept {} }; -template -const unsigned cpp_int_base::limb_bits; -template +template +const std::size_t cpp_int_base::limb_bits; +template const limb_type cpp_int_base::max_limb_value; -template +template const limb_type cpp_int_base::sign_bit_mask; -template -const unsigned cpp_int_base::internal_limb_count; +template +const std::size_t cpp_int_base::internal_limb_count; -template +template struct cpp_int_base : private boost::multiprecision::detail::empty_value::type> { @@ -531,7 +531,7 @@ struct cpp_int_base +template struct cpp_int_base { using limb_pointer = limb_type* ; @@ -540,8 +540,8 @@ struct cpp_int_base struct scoped_shared_storage { - BOOST_MP_CXX14_CONSTEXPR scoped_shared_storage(const cpp_int_base&, unsigned) {} - BOOST_MP_CXX14_CONSTEXPR void deallocate(unsigned) {} + BOOST_MP_CXX14_CONSTEXPR scoped_shared_storage(const cpp_int_base&, std::size_t) {} + BOOST_MP_CXX14_CONSTEXPR void deallocate(std::size_t) {} }; // @@ -550,10 +550,10 @@ struct cpp_int_base static_assert(MinBits > sizeof(double_limb_type) * CHAR_BIT, "Template parameter MinBits is inconsistent with the parameter trivial - did you mistakingly try to override the trivial parameter?"); public: - static constexpr unsigned limb_bits = sizeof(limb_type) * CHAR_BIT; + static constexpr std::size_t limb_bits = sizeof(limb_type) * CHAR_BIT; static constexpr limb_type max_limb_value = ~static_cast(0u); static constexpr limb_type sign_bit_mask = static_cast(1u) << (limb_bits - 1); - static constexpr unsigned internal_limb_count = MinBits / limb_bits + ((MinBits % limb_bits) ? 1 : 0); + static constexpr std::size_t internal_limb_count = MinBits / limb_bits + ((MinBits % limb_bits) ? 1 : 0); static constexpr limb_type upper_limb_mask = (MinBits % limb_bits) ? (limb_type(1) << (MinBits % limb_bits)) - 1 : (~limb_type(0)); static_assert(internal_limb_count >= 2, "A fixed precision integer type must have at least 2 limbs"); @@ -622,7 +622,7 @@ struct cpp_int_base : m_wrapper(i), m_limbs(1), m_sign(false) {} constexpr cpp_int_base(const cpp_int_base& a, const literals::detail::negate_tag&) : m_wrapper(a.m_wrapper), m_limbs(a.m_limbs), m_sign((a.m_limbs == 1) && (*a.limbs() == 0) ? false : !a.m_sign) {} - explicit constexpr cpp_int_base(scoped_shared_storage&, unsigned) noexcept : m_wrapper(), m_limbs(0), m_sign(false) + explicit constexpr cpp_int_base(scoped_shared_storage&, std::size_t) noexcept : m_wrapper(), m_limbs(0), m_sign(false) {} // // These are deprecated in C++20 unless we make them explicit: @@ -631,7 +631,7 @@ struct cpp_int_base // // Helper functions for getting at our internal data, and manipulating storage: // - BOOST_MP_FORCEINLINE constexpr unsigned size() const noexcept { return m_limbs; } + BOOST_MP_FORCEINLINE constexpr std::size_t size() const noexcept { return m_limbs; } BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR limb_pointer limbs() noexcept { return m_wrapper.m_data; } BOOST_MP_FORCEINLINE constexpr const_limb_pointer limbs() const noexcept { return m_wrapper.m_data; } BOOST_MP_FORCEINLINE constexpr bool sign() const noexcept { return m_sign; } @@ -645,7 +645,7 @@ struct cpp_int_base m_sign = false; } } - BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void resize(unsigned new_size, unsigned min_size) noexcept((Checked == unchecked)) + BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void resize(std::size_t new_size, std::size_t min_size) noexcept((Checked == unchecked)) { m_limbs = static_cast((std::min)(new_size, internal_limb_count)); detail::verify_new_size(m_limbs, min_size, checked_type()); @@ -678,7 +678,7 @@ struct cpp_int_base #ifndef BOOST_MP_NO_CONSTEXPR_DETECTION if (BOOST_MP_IS_CONST_EVALUATED(m_limbs)) { - for (unsigned i = 0; i < m_limbs; ++i) + for (std::size_t i = 0; i < m_limbs; ++i) limbs()[i] = o.limbs()[i]; } else @@ -703,7 +703,7 @@ struct cpp_int_base } BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void do_swap(cpp_int_base& o) noexcept { - for (unsigned i = 0; i < (std::max)(size(), o.size()); ++i) + for (std::size_t i = 0; i < (std::max)(size(), o.size()); ++i) std_constexpr::swap(m_wrapper.m_data[i], o.m_wrapper.m_data[i]); std_constexpr::swap(m_sign, o.m_sign); std_constexpr::swap(m_limbs, o.m_limbs); @@ -714,18 +714,18 @@ struct cpp_int_base BOOST_MP_CXX14_CONSTEXPR void check_in_range(const A&) noexcept {} }; -template -const unsigned cpp_int_base::limb_bits; -template +template +const std::size_t cpp_int_base::limb_bits; +template const limb_type cpp_int_base::max_limb_value; -template +template const limb_type cpp_int_base::sign_bit_mask; -template -const unsigned cpp_int_base::internal_limb_count; +template +const std::size_t cpp_int_base::internal_limb_count; // // Fixed precision (i.e. no allocator), unsigned type with limb-usage count: // -template +template struct cpp_int_base { using limb_pointer = limb_type* ; @@ -734,8 +734,8 @@ struct cpp_int_base struct scoped_shared_storage { - BOOST_MP_CXX14_CONSTEXPR scoped_shared_storage(const cpp_int_base&, unsigned) {} - BOOST_MP_CXX14_CONSTEXPR void deallocate(unsigned) {} + BOOST_MP_CXX14_CONSTEXPR scoped_shared_storage(const cpp_int_base&, std::size_t) {} + BOOST_MP_CXX14_CONSTEXPR void deallocate(std::size_t) {} }; // // Interface invariants: @@ -743,10 +743,10 @@ struct cpp_int_base static_assert(MinBits > sizeof(double_limb_type) * CHAR_BIT, "Template parameter MinBits is inconsistent with the parameter trivial - did you mistakingly try to override the trivial parameter?"); public: - static constexpr unsigned limb_bits = sizeof(limb_type) * CHAR_BIT; + static constexpr std::size_t limb_bits = sizeof(limb_type) * CHAR_BIT; static constexpr limb_type max_limb_value = ~static_cast(0u); static constexpr limb_type sign_bit_mask = static_cast(1u) << (limb_bits - 1); - static constexpr unsigned internal_limb_count = MinBits / limb_bits + ((MinBits % limb_bits) ? 1 : 0); + static constexpr std::size_t internal_limb_count = MinBits / limb_bits + ((MinBits % limb_bits) ? 1 : 0); static constexpr limb_type upper_limb_mask = (MinBits % limb_bits) ? (limb_type(1) << (MinBits % limb_bits)) - 1 : (~limb_type(0)); static_assert(internal_limb_count >= 2, "A fixed precision integer type must have at least 2 limbs"); @@ -781,7 +781,7 @@ struct cpp_int_base constexpr data_type(literals::detail::value_pack) : m_data{VALUES...} {} } m_wrapper; - limb_type m_limbs; + std::size_t m_limbs; public: // @@ -815,12 +815,12 @@ struct cpp_int_base {} constexpr cpp_int_base(literals::detail::value_pack<>) : m_wrapper(static_cast(0u)), m_limbs(1) {} - explicit constexpr cpp_int_base(scoped_shared_storage&, unsigned) noexcept : m_wrapper(), m_limbs(1) + explicit constexpr cpp_int_base(scoped_shared_storage&, std::size_t) noexcept : m_wrapper(), m_limbs(1) {} // // Helper functions for getting at our internal data, and manipulating storage: // - BOOST_MP_FORCEINLINE constexpr unsigned size() const noexcept { return m_limbs; } + BOOST_MP_FORCEINLINE constexpr std::size_t size() const noexcept { return m_limbs; } BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR limb_pointer limbs() noexcept { return m_wrapper.m_data; } BOOST_MP_FORCEINLINE constexpr const_limb_pointer limbs() const noexcept { return m_wrapper.m_data; } BOOST_MP_FORCEINLINE constexpr bool sign() const noexcept { return false; } @@ -829,7 +829,7 @@ struct cpp_int_base if (b) negate(); } - BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void resize(unsigned new_size, unsigned min_size) noexcept((Checked == unchecked)) + BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void resize(std::size_t new_size, std::size_t min_size) noexcept((Checked == unchecked)) { m_limbs = (std::min)(new_size, internal_limb_count); detail::verify_new_size(m_limbs, min_size, checked_type()); @@ -864,7 +864,7 @@ struct cpp_int_base #ifndef BOOST_MP_NO_CONSTEXPR_DETECTION if (BOOST_MP_IS_CONST_EVALUATED(m_limbs)) { - for (unsigned i = 0; i < m_limbs; ++i) + for (std::size_t i = 0; i < m_limbs; ++i) limbs()[i] = o.limbs()[i]; } else @@ -888,7 +888,7 @@ struct cpp_int_base if ((m_limbs == 1) && (m_wrapper.m_data[0] == 0)) return; // negating zero is always zero, and always OK. check_negate(checked_type()); - unsigned i = m_limbs; + std::size_t i = m_limbs; for (; i < internal_limb_count; ++i) m_wrapper.m_data[i] = 0; m_limbs = internal_limb_count; @@ -903,7 +903,7 @@ struct cpp_int_base } BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void do_swap(cpp_int_base& o) noexcept { - for (unsigned i = 0; i < (std::max)(size(), o.size()); ++i) + for (std::size_t i = 0; i < (std::max)(size(), o.size()); ++i) std_constexpr::swap(m_wrapper.m_data[i], o.m_wrapper.m_data[i]); std_constexpr::swap(m_limbs, o.m_limbs); } @@ -913,14 +913,14 @@ struct cpp_int_base BOOST_MP_CXX14_CONSTEXPR void check_in_range(const A&) noexcept {} }; -template -const unsigned cpp_int_base::limb_bits; -template +template +const std::size_t cpp_int_base::limb_bits; +template const limb_type cpp_int_base::max_limb_value; -template +template const limb_type cpp_int_base::sign_bit_mask; -template -const unsigned cpp_int_base::internal_limb_count; +template +const std::size_t cpp_int_base::internal_limb_count; // // Traits classes to figure out a native type with N bits, these vary from boost::uint_t only // because some platforms have native integer types longer than long long, "really long long" anyone?? @@ -943,7 +943,7 @@ struct trivial_limb_type : public trivial_limb_type_imp +template struct cpp_int_base { using local_limb_type = typename trivial_limb_type::type; @@ -953,12 +953,12 @@ struct cpp_int_base struct scoped_shared_storage { - BOOST_MP_CXX14_CONSTEXPR scoped_shared_storage(const cpp_int_base&, unsigned) {} - BOOST_MP_CXX14_CONSTEXPR void deallocate(unsigned) {} + BOOST_MP_CXX14_CONSTEXPR scoped_shared_storage(const cpp_int_base&, std::size_t) {} + BOOST_MP_CXX14_CONSTEXPR void deallocate(std::size_t) {} }; protected: - static constexpr unsigned limb_bits = sizeof(local_limb_type) * CHAR_BIT; + static constexpr std::size_t limb_bits = sizeof(local_limb_type) * CHAR_BIT; static constexpr local_limb_type limb_mask = (MinBits < limb_bits) ? local_limb_type((local_limb_type(~local_limb_type(0))) >> (limb_bits - MinBits)) : local_limb_type(~local_limb_type(0)); private: @@ -1064,12 +1064,12 @@ struct cpp_int_base // BOOST_MP_CXX14_CONSTEXPR cpp_int_base& operator=(const cpp_int_base&) = default; - explicit constexpr cpp_int_base(scoped_shared_storage&, unsigned) noexcept : m_data(0), m_sign(false) + explicit constexpr cpp_int_base(scoped_shared_storage&, std::size_t) noexcept : m_data(0), m_sign(false) {} // // Helper functions for getting at our internal data, and manipulating storage: // - BOOST_MP_FORCEINLINE constexpr unsigned size() const noexcept { return 1; } + BOOST_MP_FORCEINLINE constexpr std::size_t size() const noexcept { return 1; } BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR limb_pointer limbs() noexcept { return &m_data; } BOOST_MP_FORCEINLINE constexpr const_limb_pointer limbs() const noexcept { return &m_data; } BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR bool sign() const noexcept { return m_sign; } @@ -1082,7 +1082,7 @@ struct cpp_int_base m_sign = false; } } - BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void resize(unsigned /* new_size */, unsigned min_size) + BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void resize(std::size_t /* new_size */, std::size_t min_size) { detail::verify_new_size(2, min_size, checked_type()); } @@ -1126,7 +1126,7 @@ struct cpp_int_base // // Backend for unsigned fixed precision (i.e. no allocator) type which will fit entirely inside a "double_limb_type": // -template +template struct cpp_int_base { using local_limb_type = typename trivial_limb_type::type; @@ -1135,12 +1135,12 @@ struct cpp_int_base struct scoped_shared_storage { - BOOST_MP_CXX14_CONSTEXPR scoped_shared_storage(const cpp_int_base&, unsigned) {} - BOOST_MP_CXX14_CONSTEXPR void deallocate(unsigned) {} + BOOST_MP_CXX14_CONSTEXPR scoped_shared_storage(const cpp_int_base&, std::size_t) {} + BOOST_MP_CXX14_CONSTEXPR void deallocate(std::size_t) {} }; private: - static constexpr unsigned limb_bits = sizeof(local_limb_type) * CHAR_BIT; + static constexpr std::size_t limb_bits = sizeof(local_limb_type) * CHAR_BIT; static constexpr local_limb_type limb_mask = limb_bits != MinBits ? static_cast(static_cast(~local_limb_type(0)) >> (limb_bits - MinBits)) : static_cast(~local_limb_type(0)); @@ -1237,12 +1237,12 @@ struct cpp_int_base // BOOST_MP_CXX14_CONSTEXPR cpp_int_base& operator=(const cpp_int_base&) = default; - explicit constexpr cpp_int_base(scoped_shared_storage&, unsigned) noexcept : m_data(0) + explicit constexpr cpp_int_base(scoped_shared_storage&, std::size_t) noexcept : m_data(0) {} // // Helper functions for getting at our internal data, and manipulating storage: // - BOOST_MP_FORCEINLINE constexpr unsigned size() const noexcept { return 1; } + BOOST_MP_FORCEINLINE constexpr std::size_t size() const noexcept { return 1; } BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR limb_pointer limbs() noexcept { return &m_data; } BOOST_MP_FORCEINLINE constexpr const_limb_pointer limbs() const noexcept { return &m_data; } BOOST_MP_FORCEINLINE constexpr bool sign() const noexcept { return false; } @@ -1251,7 +1251,7 @@ struct cpp_int_base if (b) negate(); } - BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void resize(unsigned, unsigned min_size) + BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR void resize(unsigned, std::size_t min_size) { detail::verify_new_size(2, min_size, checked_type()); } @@ -1304,7 +1304,7 @@ struct is_allowed_cpp_int_base_conversion : public std::conditional< // // Now the actual backend, normalising parameters passed to the base class: // -template +template struct cpp_int_backend : public cpp_int_base< min_precision >::value, @@ -1348,7 +1348,7 @@ struct cpp_int_backend BOOST_MP_FORCEINLINE constexpr cpp_int_backend(cpp_int_backend&& o) noexcept : base_type(static_cast(o)) {} - template + template BOOST_MP_FORCEINLINE BOOST_CXX14_CONSTEXPR cpp_int_backend(cpp_int_backend&& o, typename std::enable_if, self_type>::value>::type* = nullptr) noexcept { *this = static_cast&&>(o); @@ -1363,15 +1363,15 @@ struct cpp_int_backend // Aliasing constructor: the result will alias the memory referenced, unless // we have fixed precision and storage, in which case we copy the memory: // - explicit constexpr cpp_int_backend(limb_type* data, unsigned offset, unsigned len) noexcept + explicit constexpr cpp_int_backend(limb_type* data, std::size_t offset, std::size_t len) noexcept : base_type(data, offset, len) {} - explicit cpp_int_backend(const limb_type* data, unsigned offset, unsigned len) noexcept + explicit cpp_int_backend(const limb_type* data, std::size_t offset, std::size_t len) noexcept : base_type(data, offset, len) { this->normalize(); } - explicit constexpr cpp_int_backend(typename base_type::scoped_shared_storage& data, unsigned len) noexcept + explicit constexpr cpp_int_backend(typename base_type::scoped_shared_storage& data, std::size_t len) noexcept : base_type(data, len) {} private: - template + template BOOST_MP_CXX14_CONSTEXPR void do_assign(const cpp_int_backend& other, std::integral_constant const&, std::integral_constant const&) { // Assigning trivial type to trivial type: @@ -1380,7 +1380,7 @@ struct cpp_int_backend this->sign(other.sign()); this->normalize(); } - template + template BOOST_MP_CXX14_CONSTEXPR void do_assign(const cpp_int_backend& other, std::integral_constant const&, std::integral_constant const&) { // non-trivial to trivial narrowing conversion: @@ -1400,7 +1400,7 @@ struct cpp_int_backend this->sign(other.sign()); this->normalize(); } - template + template BOOST_MP_CXX14_CONSTEXPR void do_assign(const cpp_int_backend& other, std::integral_constant const&, std::integral_constant const&) { // trivial to non-trivial, treat the trivial argument as if it were an unsigned arithmetic type, then set the sign afterwards: @@ -1410,22 +1410,22 @@ struct cpp_int_backend cpp_int_backend >::type>(*other.limbs()); this->sign(other.sign()); } - template + template BOOST_MP_CXX14_CONSTEXPR void do_assign(const cpp_int_backend& other, std::integral_constant const&, std::integral_constant const&) { // regular non-trivial to non-trivial assign: this->resize(other.size(), other.size()); #if !defined(BOOST_MP_HAS_IS_CONSTANT_EVALUATED) && !defined(BOOST_MP_HAS_BUILTIN_IS_CONSTANT_EVALUATED) && !defined(BOOST_NO_CXX14_CONSTEXPR) - unsigned count = (std::min)(other.size(), this->size()); - for (unsigned i = 0; i < count; ++i) + std::size_t count = (std::min)(other.size(), this->size()); + for (std::size_t i = 0; i < count; ++i) this->limbs()[i] = other.limbs()[i]; #else #ifndef BOOST_MP_NO_CONSTEXPR_DETECTION if (BOOST_MP_IS_CONST_EVALUATED(other.size())) { - unsigned count = (std::min)(other.size(), this->size()); - for (unsigned i = 0; i < count; ++i) + std::size_t count = (std::min)(other.size(), this->size()); + for (std::size_t i = 0; i < count; ++i) this->limbs()[i] = other.limbs()[i]; } else @@ -1437,7 +1437,7 @@ struct cpp_int_backend } public: - template + template BOOST_MP_CXX14_CONSTEXPR cpp_int_backend( const cpp_int_backend& other, typename std::enable_if, self_type>::value>::type* = nullptr) @@ -1448,7 +1448,7 @@ struct cpp_int_backend std::integral_constant::value>(), std::integral_constant >::value>()); } - template + template explicit BOOST_MP_CXX14_CONSTEXPR cpp_int_backend( const cpp_int_backend& other, typename std::enable_if< !(is_implicit_cpp_int_conversion, self_type>::value)>::type* = nullptr) @@ -1459,7 +1459,7 @@ struct cpp_int_backend std::integral_constant::value>(), std::integral_constant >::value>()); } - template + template BOOST_MP_CXX14_CONSTEXPR cpp_int_backend& operator=( const cpp_int_backend& other) { @@ -1484,7 +1484,7 @@ struct cpp_int_backend *static_cast(this) = static_cast(o); return *this; } - template + template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<((MaxBits2 <= MaxBits) || (MaxBits == 0)) && !std::is_void::value, cpp_int_backend&>::type operator=(cpp_int_backend&& o) noexcept { *static_cast(this) = static_cast::base_type&&>(o); @@ -1888,7 +1888,7 @@ struct cpp_int_backend base = 16; std::string result; - unsigned Bits = sizeof(typename base_type::local_limb_type) * CHAR_BIT; + std::size_t Bits = sizeof(typename base_type::local_limb_type) * CHAR_BIT; if (base == 8 || base == 16) { @@ -1900,7 +1900,7 @@ struct cpp_int_backend result.assign(Bits / shift + (Bits % shift ? 1 : 0), '0'); std::string::difference_type pos = result.size() - 1; char letter_a = f & std::ios_base::uppercase ? 'A' : 'a'; - for (unsigned i = 0; i < Bits / shift; ++i) + for (std::size_t i = 0; i < Bits / shift; ++i) { char c = '0' + static_cast(v & mask); if (c > '9') @@ -1974,7 +1974,7 @@ struct cpp_int_backend base = 16; std::string result; - unsigned Bits = this->size() * base_type::limb_bits; + std::size_t Bits = this->size() * base_type::limb_bits; if (base == 8 || base == 16) { @@ -1986,7 +1986,7 @@ struct cpp_int_backend result.assign(Bits / shift + ((Bits % shift) ? 1 : 0), '0'); std::string::difference_type pos = result.size() - 1; char letter_a = f & std::ios_base::uppercase ? 'A' : 'a'; - for (unsigned i = 0; i < Bits / shift; ++i) + for (std::size_t i = 0; i < Bits / shift; ++i) { char c = '0' + static_cast(t.limbs()[0] & mask); if (c > '9') @@ -2041,7 +2041,7 @@ struct cpp_int_backend divide_unsigned_helper(&t2, t, block10, r); t = t2; limb_type v = r.limbs()[0]; - for (unsigned i = 0; i < digits_per_block_10; ++i) + for (std::size_t i = 0; i < digits_per_block_10; ++i) { char c = '0' + v % 10; v /= 10; @@ -2076,7 +2076,7 @@ struct cpp_int_backend // // We assume that c is a sequence of (unsigned) bytes with the most significant byte first: // - unsigned newsize = static_cast(c.size() / sizeof(limb_type)); + std::size_t newsize = static_cast(c.size() / sizeof(limb_type)); if (c.size() % sizeof(limb_type)) { ++newsize; @@ -2086,11 +2086,11 @@ struct cpp_int_backend this->resize(newsize, newsize); // May throw std::memset(this->limbs(), 0, this->size()); typename Container::const_iterator i(c.begin()), j(c.end()); - unsigned byte_location = static_cast(c.size() - 1); + std::size_t byte_location = static_cast(c.size() - 1); while (i != j) { - unsigned limb = byte_location / sizeof(limb_type); - unsigned shift = (byte_location % sizeof(limb_type)) * CHAR_BIT; + std::size_t limb = byte_location / sizeof(limb_type); + std::size_t shift = (byte_location % sizeof(limb_type)) * CHAR_BIT; if (this->size() > limb) this->limbs()[limb] |= static_cast(static_cast(*i)) << shift; ++i; @@ -2109,11 +2109,11 @@ struct cpp_int_backend if (c.size()) { typename Container::const_iterator i(c.begin()), j(c.end()); - unsigned byte_location = static_cast(c.size() - 1); + std::size_t byte_location = static_cast(c.size() - 1); while (i != j) { - unsigned limb = byte_location / sizeof(local_limb_type); - unsigned shift = (byte_location % sizeof(local_limb_type)) * CHAR_BIT; + std::size_t limb = byte_location / sizeof(local_limb_type); + std::size_t shift = (byte_location % sizeof(local_limb_type)) * CHAR_BIT; if (limb == 0) this->limbs()[0] |= static_cast(static_cast(*i)) << shift; ++i; @@ -2131,7 +2131,7 @@ struct cpp_int_backend // construct_from_container(c, trivial_tag()); } - template + template BOOST_MP_CXX14_CONSTEXPR int compare_imp(const cpp_int_backend& o, const std::integral_constant&, const std::integral_constant&) const noexcept { if (this->sign() != o.sign()) @@ -2144,19 +2144,19 @@ struct cpp_int_backend result = -result; return result; } - template + template BOOST_MP_CXX14_CONSTEXPR int compare_imp(const cpp_int_backend& o, const std::integral_constant&, const std::integral_constant&) const { cpp_int_backend t(*this); return t.compare(o); } - template + template BOOST_MP_CXX14_CONSTEXPR int compare_imp(const cpp_int_backend& o, const std::integral_constant&, const std::integral_constant&) const { cpp_int_backend t(o); return compare(t); } - template + template BOOST_MP_CXX14_CONSTEXPR int compare_imp(const cpp_int_backend& o, const std::integral_constant&, const std::integral_constant&) const noexcept { if (this->sign()) @@ -2175,14 +2175,14 @@ struct cpp_int_backend return *this->limbs() < *o.limbs() ? -1 : (*this->limbs() > *o.limbs() ? 1 : 0); } } - template + template BOOST_MP_CXX14_CONSTEXPR int compare(const cpp_int_backend& o) const noexcept { using t1 = std::integral_constant >::value> ; using t2 = std::integral_constant >::value>; return compare_imp(o, t1(), t2()); } - template + template BOOST_MP_CXX14_CONSTEXPR int compare_unsigned(const cpp_int_backend& o) const noexcept { if (this->size() != o.size()) @@ -2191,7 +2191,7 @@ struct cpp_int_backend } typename base_type::const_limb_pointer pa = this->limbs(); typename base_type::const_limb_pointer pb = o.limbs(); - for (int i = this->size() - 1; i >= 0; --i) + for (std::ptrdiff_t i = this->size() - 1; i >= 0; --i) { if (pa[i] != pb[i]) return pa[i] > pb[i] ? 1 : -1; @@ -2215,7 +2215,7 @@ namespace default_ops { template struct double_precision_type; -template +template struct double_precision_type > { using type = typename std::conditional< @@ -2232,11 +2232,11 @@ struct double_precision_type +template struct is_equivalent_number_type, backends::cpp_int_backend > : public std::integral_constant, et_on> >::digits == std::numeric_limits, et_on> >::digits>{}; -template +template struct expression_template_default > { static constexpr const expression_template_option value = et_off; @@ -2244,7 +2244,7 @@ struct expression_template_default +template struct number_category > : public std::integral_constant {}; diff --git a/include/boost/multiprecision/cpp_int/add.hpp b/include/boost/multiprecision/cpp_int/add.hpp index 6f587a87..0d6a34eb 100644 --- a/include/boost/multiprecision/cpp_int/add.hpp +++ b/include/boost/multiprecision/cpp_int/add.hpp @@ -26,7 +26,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void add_unsigned(CppInt1& result, const CppInt2 double_limb_type carry = o; typename CppInt1::limb_pointer pr = result.limbs(); typename CppInt2::const_limb_pointer pa = a.limbs(); - unsigned i = 0; + std::size_t i = 0; // Addition with carry until we either run out of digits or carry is zero: for (; carry && (i < result.size()); ++i) { @@ -46,7 +46,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void add_unsigned(CppInt1& result, const CppInt2 if (carry) { // We overflowed, need to add one more limb: - unsigned x = result.size(); + std::size_t x = result.size(); result.resize(x + 1, x + 1); if (result.size() > x) result.limbs()[x] = static_cast(carry); @@ -87,7 +87,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void subtract_unsigned(CppInt1& result, const Cp else { *pr = static_cast((borrow + *pa) - b); - unsigned i = 1; + std::size_t i = 1; while (!pa[i]) { pr[i] = CppInt1::max_limb_value; @@ -107,7 +107,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void subtract_unsigned(CppInt1& result, const Cp // // Now the actual functions called by the front end, all of which forward to one of the above: // -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_add( cpp_int_backend& result, @@ -115,7 +115,7 @@ eval_add( { eval_add(result, result, o); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value && !is_trivial_cpp_int >::value>::type eval_add( cpp_int_backend& result, @@ -129,7 +129,7 @@ eval_add( } add_unsigned(result, a, b); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_add(cpp_int_backend& result, const limb_type& o) noexcept((is_non_throwing_cpp_int >::value)) { @@ -140,7 +140,7 @@ eval_add(cpp_int_backend& r else add_unsigned(result, result, o); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_add( cpp_int_backend& result, @@ -154,7 +154,7 @@ eval_add( else add_unsigned(result, a, o); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_add( cpp_int_backend& result, @@ -165,7 +165,7 @@ eval_add( else if (o > 0) eval_add(result, static_cast(o)); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_add( cpp_int_backend& result, @@ -179,7 +179,7 @@ eval_add( else if (&result != &a) result = a; } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_subtract( cpp_int_backend& result, @@ -192,7 +192,7 @@ eval_subtract( else subtract_unsigned(result, result, o); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_subtract( cpp_int_backend& result, @@ -208,7 +208,7 @@ eval_subtract( subtract_unsigned(result, a, o); } } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_subtract( cpp_int_backend& result, @@ -222,7 +222,7 @@ eval_subtract( eval_subtract(result, static_cast(o)); } } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_subtract( cpp_int_backend& result, @@ -240,7 +240,7 @@ eval_subtract( result = a; } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_increment(cpp_int_backend& result) noexcept((is_non_throwing_cpp_int >::value)) { @@ -257,7 +257,7 @@ eval_increment(cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_decrement(cpp_int_backend& result) noexcept((is_non_throwing_cpp_int >::value)) { @@ -270,7 +270,7 @@ eval_decrement(cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_subtract( cpp_int_backend& result, @@ -278,7 +278,7 @@ eval_subtract( { eval_subtract(result, result, o); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value && !is_trivial_cpp_int >::value>::type eval_subtract( cpp_int_backend& result, @@ -298,7 +298,7 @@ eval_subtract( // // One of the arguments is signed: // -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && (is_signed_number >::value || is_signed_number >::value)>::type eval_add( @@ -320,7 +320,7 @@ eval_add( result.normalize(); } // Simple version for two unsigned arguments: -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && is_unsigned_number >::value && is_unsigned_number >::value>::type eval_add(cpp_int_backend& result, @@ -331,7 +331,7 @@ eval_add(cpp_int_backend& } // signed subtraction: -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && (is_signed_number >::value || is_signed_number >::value)>::type eval_subtract( @@ -352,7 +352,7 @@ eval_subtract( result.normalize(); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && is_unsigned_number >::value && is_unsigned_number >::value>::type eval_subtract( diff --git a/include/boost/multiprecision/cpp_int/add_unsigned.hpp b/include/boost/multiprecision/cpp_int/add_unsigned.hpp index b82a3a7c..a433dafe 100644 --- a/include/boost/multiprecision/cpp_int/add_unsigned.hpp +++ b/include/boost/multiprecision/cpp_int/add_unsigned.hpp @@ -22,9 +22,9 @@ inline BOOST_MP_CXX14_CONSTEXPR void add_unsigned_constexpr(CppInt1& result, con // Nothing fancy, just let uintmax_t take the strain: // double_limb_type carry = 0; - unsigned m(0), x(0); - unsigned as = a.size(); - unsigned bs = b.size(); + std::size_t m(0), x(0); + std::size_t as = a.size(); + std::size_t bs = b.size(); minmax(as, bs, m, x); if (x == 1) { @@ -96,7 +96,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void subtract_unsigned_constexpr(CppInt1& result // Nothing fancy, just let uintmax_t take the strain: // double_limb_type borrow = 0; - unsigned m(0), x(0); + std::size_t m(0), x(0); minmax(a.size(), b.size(), m, x); // // special cases for small limb counts: @@ -136,7 +136,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void subtract_unsigned_constexpr(CppInt1& result return; } - unsigned i = 0; + std::size_t i = 0; // First where a and b overlap: while (i < m) { @@ -199,9 +199,9 @@ inline BOOST_MP_CXX14_CONSTEXPR void add_unsigned(CppInt1& result, const CppInt2 using std::swap; // Nothing fancy, just let uintmax_t take the strain: - unsigned m(0), x(0); - unsigned as = a.size(); - unsigned bs = b.size(); + std::size_t m(0), x(0); + std::size_t as = a.size(); + std::size_t bs = b.size(); minmax(as, bs, m, x); if (x == 1) { @@ -218,7 +218,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void add_unsigned(CppInt1& result, const CppInt2 if (as < bs) swap(pa, pb); // First where a and b overlap: - unsigned i = 0; + std::size_t i = 0; unsigned char carry = 0; #if defined(BOOST_MSVC) && !defined(BOOST_HAS_INT128) && defined(_M_X64) // @@ -273,7 +273,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void subtract_unsigned(CppInt1& result, const Cp using std::swap; // Nothing fancy, just let uintmax_t take the strain: - unsigned m(0), x(0); + std::size_t m(0), x(0); minmax(a.size(), b.size(), m, x); // // special cases for small limb counts: @@ -313,7 +313,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void subtract_unsigned(CppInt1& result, const Cp return; } - unsigned i = 0; + std::size_t i = 0; unsigned char borrow = 0; // First where a and b overlap: #if defined(BOOST_MSVC) && !defined(BOOST_HAS_INT128) && defined(_M_X64) diff --git a/include/boost/multiprecision/cpp_int/bitwise.hpp b/include/boost/multiprecision/cpp_int/bitwise.hpp index 4cc8a64d..421c5f20 100644 --- a/include/boost/multiprecision/cpp_int/bitwise.hpp +++ b/include/boost/multiprecision/cpp_int/bitwise.hpp @@ -21,7 +21,7 @@ namespace boost { namespace multiprecision { namespace backends { -template +template BOOST_MP_CXX14_CONSTEXPR void is_valid_bitwise_op( cpp_int_backend& result, const cpp_int_backend& o, const std::integral_constant&) @@ -30,12 +30,12 @@ BOOST_MP_CXX14_CONSTEXPR void is_valid_bitwise_op( BOOST_MP_THROW_EXCEPTION(std::range_error("Bitwise operations on negative values results in undefined behavior.")); } -template +template BOOST_MP_CXX14_CONSTEXPR void is_valid_bitwise_op( cpp_int_backend&, const cpp_int_backend&, const std::integral_constant&) {} -template +template BOOST_MP_CXX14_CONSTEXPR void is_valid_bitwise_op( const cpp_int_backend& result, const std::integral_constant&) { @@ -43,11 +43,11 @@ BOOST_MP_CXX14_CONSTEXPR void is_valid_bitwise_op( BOOST_MP_THROW_EXCEPTION(std::range_error("Bitwise operations on negative values results in undefined behavior.")); } -template +template BOOST_MP_CXX14_CONSTEXPR void is_valid_bitwise_op( const cpp_int_backend&, const std::integral_constant&) {} -template +template BOOST_MP_CXX14_CONSTEXPR void is_valid_bitwise_op( cpp_int_backend&, const std::integral_constant&) {} @@ -74,14 +74,14 @@ BOOST_MP_CXX14_CONSTEXPR void bitwise_op( // // First figure out how big the result needs to be and set up some data: // - unsigned rs = result.size(); - unsigned os = o.size(); - unsigned m(0), x(0); + std::size_t rs = result.size(); + std::size_t os = o.size(); + std::size_t m(0), x(0); minmax(rs, os, m, x); result.resize(x, x); typename CppInt1::limb_pointer pr = result.limbs(); typename CppInt2::const_limb_pointer po = o.limbs(); - for (unsigned i = rs; i < x; ++i) + for (std::size_t i = rs; i < x; ++i) pr[i] = 0; limb_type next_limb = 0; @@ -90,22 +90,22 @@ BOOST_MP_CXX14_CONSTEXPR void bitwise_op( { if (!o.sign()) { - for (unsigned i = 0; i < os; ++i) + for (std::size_t i = 0; i < os; ++i) pr[i] = op(pr[i], po[i]); - for (unsigned i = os; i < x; ++i) + for (std::size_t i = os; i < x; ++i) pr[i] = op(pr[i], limb_type(0)); } else { // "o" is negative: double_limb_type carry = 1; - for (unsigned i = 0; i < os; ++i) + for (std::size_t i = 0; i < os; ++i) { carry += static_cast(~po[i]); pr[i] = op(pr[i], static_cast(carry)); carry >>= CppInt1::limb_bits; } - for (unsigned i = os; i < x; ++i) + for (std::size_t i = os; i < x; ++i) { carry += static_cast(~limb_type(0)); pr[i] = op(pr[i], static_cast(carry)); @@ -122,13 +122,13 @@ BOOST_MP_CXX14_CONSTEXPR void bitwise_op( { // "result" is negative: double_limb_type carry = 1; - for (unsigned i = 0; i < os; ++i) + for (std::size_t i = 0; i < os; ++i) { carry += static_cast(~pr[i]); pr[i] = op(static_cast(carry), po[i]); carry >>= CppInt1::limb_bits; } - for (unsigned i = os; i < x; ++i) + for (std::size_t i = os; i < x; ++i) { carry += static_cast(~pr[i]); pr[i] = op(static_cast(carry), limb_type(0)); @@ -143,7 +143,7 @@ BOOST_MP_CXX14_CONSTEXPR void bitwise_op( // both are negative: double_limb_type r_carry = 1; double_limb_type o_carry = 1; - for (unsigned i = 0; i < os; ++i) + for (std::size_t i = 0; i < os; ++i) { r_carry += static_cast(~pr[i]); o_carry += static_cast(~po[i]); @@ -151,7 +151,7 @@ BOOST_MP_CXX14_CONSTEXPR void bitwise_op( r_carry >>= CppInt1::limb_bits; o_carry >>= CppInt1::limb_bits; } - for (unsigned i = os; i < x; ++i) + for (std::size_t i = os; i < x; ++i) { r_carry += static_cast(~pr[i]); o_carry += static_cast(~limb_type(0)); @@ -171,7 +171,7 @@ BOOST_MP_CXX14_CONSTEXPR void bitwise_op( if (static_cast(next_limb) < 0) { double_limb_type carry = 1; - for (unsigned i = 0; i < x; ++i) + for (std::size_t i = 0; i < x; ++i) { carry += static_cast(~pr[i]); pr[i] = static_cast(carry); @@ -202,19 +202,19 @@ BOOST_MP_CXX14_CONSTEXPR void bitwise_op( // // First figure out how big the result needs to be and set up some data: // - unsigned rs = result.size(); - unsigned os = o.size(); - unsigned m(0), x(0); + std::size_t rs = result.size(); + std::size_t os = o.size(); + std::size_t m(0), x(0); minmax(rs, os, m, x); result.resize(x, x); typename CppInt1::limb_pointer pr = result.limbs(); typename CppInt2::const_limb_pointer po = o.limbs(); - for (unsigned i = rs; i < x; ++i) + for (std::size_t i = rs; i < x; ++i) pr[i] = 0; - for (unsigned i = 0; i < os; ++i) + for (std::size_t i = 0; i < os; ++i) pr[i] = op(pr[i], po[i]); - for (unsigned i = os; i < x; ++i) + for (std::size_t i = os; i < x; ++i) pr[i] = op(pr[i], limb_type(0)); result.normalize(); @@ -233,7 +233,7 @@ struct bit_xor BOOST_MP_CXX14_CONSTEXPR limb_type operator()(limb_type a, limb_type b) const noexcept { return a ^ b; } }; -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_bitwise_and( cpp_int_backend& result, @@ -243,7 +243,7 @@ eval_bitwise_and( std::integral_constant > >::is_signed || std::numeric_limits > >::is_signed > ()); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_bitwise_or( cpp_int_backend& result, @@ -253,7 +253,7 @@ eval_bitwise_or( std::integral_constant > >::is_signed || std::numeric_limits > >::is_signed > ()); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_bitwise_xor( cpp_int_backend& result, @@ -265,7 +265,7 @@ eval_bitwise_xor( // // Again for operands which are single limbs: // -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_bitwise_and( cpp_int_backend& result, @@ -275,7 +275,7 @@ eval_bitwise_and( result.resize(1, 1); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_bitwise_or( cpp_int_backend& result, @@ -284,7 +284,7 @@ eval_bitwise_or( result.limbs()[0] |= l; } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_bitwise_xor( cpp_int_backend& result, @@ -293,7 +293,7 @@ eval_bitwise_xor( result.limbs()[0] ^= l; } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value && !is_trivial_cpp_int >::value>::type eval_complement( cpp_int_backend& result, @@ -306,17 +306,17 @@ eval_complement( result.negate(); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value && !is_trivial_cpp_int >::value>::type eval_complement( cpp_int_backend& result, const cpp_int_backend& o) noexcept((is_non_throwing_cpp_int >::value)) { - unsigned os = o.size(); + std::size_t os = o.size(); result.resize(UINT_MAX, os); - for (unsigned i = 0; i < os; ++i) + for (std::size_t i = 0; i < os; ++i) result.limbs()[i] = ~o.limbs()[i]; - for (unsigned i = os; i < result.size(); ++i) + for (std::size_t i = os; i < result.size(); ++i) result.limbs()[i] = ~static_cast(0); result.normalize(); } @@ -326,10 +326,10 @@ inline void left_shift_byte(Int& result, double_limb_type s) { limb_type offset = static_cast(s / Int::limb_bits); limb_type shift = static_cast(s % Int::limb_bits); - unsigned ors = result.size(); + std::size_t ors = result.size(); if ((ors == 1) && (!*result.limbs())) return; // shifting zero yields zero. - unsigned rs = ors; + std::size_t rs = ors; if (shift && (result.limbs()[ors - 1] >> (Int::limb_bits - shift))) ++rs; // Most significant limb will overflow when shifted rs += offset; @@ -358,10 +358,10 @@ inline BOOST_MP_CXX14_CONSTEXPR void left_shift_limb(Int& result, double_limb_ty limb_type offset = static_cast(s / Int::limb_bits); limb_type shift = static_cast(s % Int::limb_bits); - unsigned ors = result.size(); + std::size_t ors = result.size(); if ((ors == 1) && (!*result.limbs())) return; // shifting zero yields zero. - unsigned rs = ors; + std::size_t rs = ors; if (shift && (result.limbs()[ors - 1] >> (Int::limb_bits - shift))) ++rs; // Most significant limb will overflow when shifted rs += offset; @@ -376,7 +376,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void left_shift_limb(Int& result, double_limb_ty return; } - unsigned i = rs - result.size(); + std::size_t i = rs - result.size(); for (; i < ors; ++i) pr[rs - 1 - i] = pr[ors - 1 - i]; for (; i < rs; ++i) @@ -389,10 +389,10 @@ inline BOOST_MP_CXX14_CONSTEXPR void left_shift_generic(Int& result, double_limb limb_type offset = static_cast(s / Int::limb_bits); limb_type shift = static_cast(s % Int::limb_bits); - unsigned ors = result.size(); + std::size_t ors = result.size(); if ((ors == 1) && (!*result.limbs())) return; // shifting zero yields zero. - unsigned rs = ors; + std::size_t rs = ors; if (shift && (result.limbs()[ors - 1] >> (Int::limb_bits - shift))) ++rs; // Most significant limb will overflow when shifted rs += offset; @@ -408,7 +408,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void left_shift_generic(Int& result, double_limb return; } - unsigned i = rs - result.size(); + std::size_t i = rs - result.size(); // This code only works when shift is non-zero, otherwise we invoke undefined behaviour! BOOST_MP_ASSERT(shift); if (!truncated) @@ -440,7 +440,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void left_shift_generic(Int& result, double_limb pr[rs - 1 - i] = 0; } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_left_shift( cpp_int_backend& result, @@ -503,8 +503,8 @@ inline void right_shift_byte(Int& result, double_limb_type s) { limb_type offset = static_cast(s / Int::limb_bits); BOOST_MP_ASSERT((s % CHAR_BIT) == 0); - unsigned ors = result.size(); - unsigned rs = ors; + std::size_t ors = result.size(); + std::size_t rs = ors; if (offset >= rs) { result = limb_type(0); @@ -530,8 +530,8 @@ inline BOOST_MP_CXX14_CONSTEXPR void right_shift_limb(Int& result, double_limb_t { limb_type offset = static_cast(s / Int::limb_bits); BOOST_MP_ASSERT((s % Int::limb_bits) == 0); - unsigned ors = result.size(); - unsigned rs = ors; + std::size_t ors = result.size(); + std::size_t rs = ors; if (offset >= rs) { result = limb_type(0); @@ -539,7 +539,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void right_shift_limb(Int& result, double_limb_t } rs -= offset; typename Int::limb_pointer pr = result.limbs(); - unsigned i = 0; + std::size_t i = 0; for (; i < rs; ++i) pr[i] = pr[i + offset]; result.resize(rs, rs); @@ -550,8 +550,8 @@ inline BOOST_MP_CXX14_CONSTEXPR void right_shift_generic(Int& result, double_lim { limb_type offset = static_cast(s / Int::limb_bits); limb_type shift = static_cast(s % Int::limb_bits); - unsigned ors = result.size(); - unsigned rs = ors; + std::size_t ors = result.size(); + std::size_t rs = ors; if (offset >= rs) { result = limb_type(0); @@ -567,7 +567,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void right_shift_generic(Int& result, double_lim return; } } - unsigned i = 0; + std::size_t i = 0; // This code only works for non-zero shift, otherwise we invoke undefined behaviour! BOOST_MP_ASSERT(shift); @@ -580,7 +580,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void right_shift_generic(Int& result, double_lim result.resize(rs, rs); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_right_shift( cpp_int_backend& result, @@ -623,7 +623,7 @@ eval_right_shift( else right_shift_generic(result, s); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_right_shift( cpp_int_backend& result, @@ -676,7 +676,7 @@ eval_right_shift( // // Over again for trivial cpp_int's: // -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value >::type eval_left_shift(cpp_int_backend& result, T s) noexcept((is_non_throwing_cpp_int >::value)) { @@ -685,7 +685,7 @@ eval_left_shift(cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value >::type eval_right_shift(cpp_int_backend& result, T s) noexcept((is_non_throwing_cpp_int >::value)) { @@ -696,7 +696,7 @@ eval_right_shift(cpp_int_backend(-1); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && (is_signed_number >::value || is_signed_number >::value)>::type eval_complement( @@ -720,7 +720,7 @@ eval_complement( result.normalize(); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && is_unsigned_number >::value && is_unsigned_number >::value>::type eval_complement( @@ -731,7 +731,7 @@ eval_complement( result.normalize(); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && is_unsigned_number >::value && is_unsigned_number >::value>::type eval_bitwise_and( @@ -741,7 +741,7 @@ eval_bitwise_and( *result.limbs() &= *o.limbs(); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && (is_signed_number >::value || is_signed_number >::value)>::type eval_bitwise_and( @@ -755,7 +755,7 @@ eval_bitwise_and( if (result.sign() || o.sign()) { - constexpr const unsigned m = detail::static_unsigned_max::value, detail::static_unsigned_max::value>::value; + constexpr const std::size_t m = detail::static_unsigned_max::value, detail::static_unsigned_max::value>::value; cpp_int_backend t1(result); cpp_int_backend t2(o); eval_bitwise_and(t1, t2); @@ -774,7 +774,7 @@ eval_bitwise_and( } } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && is_unsigned_number >::value && is_unsigned_number >::value>::type eval_bitwise_or( @@ -784,7 +784,7 @@ eval_bitwise_or( *result.limbs() |= *o.limbs(); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && (is_signed_number >::value || is_signed_number >::value)>::type eval_bitwise_or( @@ -798,7 +798,7 @@ eval_bitwise_or( if (result.sign() || o.sign()) { - constexpr const unsigned m = detail::static_unsigned_max::value, detail::static_unsigned_max::value>::value; + constexpr const std::size_t m = detail::static_unsigned_max::value, detail::static_unsigned_max::value>::value; cpp_int_backend t1(result); cpp_int_backend t2(o); eval_bitwise_or(t1, t2); @@ -818,7 +818,7 @@ eval_bitwise_or( } } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && is_unsigned_number >::value && is_unsigned_number >::value>::type eval_bitwise_xor( @@ -828,7 +828,7 @@ eval_bitwise_xor( *result.limbs() ^= *o.limbs(); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && (is_signed_number >::value || is_signed_number >::value)>::type eval_bitwise_xor( @@ -842,7 +842,7 @@ eval_bitwise_xor( if (result.sign() || o.sign()) { - constexpr const unsigned m = detail::static_unsigned_max::value, detail::static_unsigned_max::value>::value; + constexpr const std::size_t m = detail::static_unsigned_max::value, detail::static_unsigned_max::value>::value; cpp_int_backend t1(result); cpp_int_backend t2(o); eval_bitwise_xor(t1, t2); diff --git a/include/boost/multiprecision/cpp_int/comparison.hpp b/include/boost/multiprecision/cpp_int/comparison.hpp index 481cc7c1..9808889f 100644 --- a/include/boost/multiprecision/cpp_int/comparison.hpp +++ b/include/boost/multiprecision/cpp_int/comparison.hpp @@ -20,7 +20,7 @@ namespace boost { namespace multiprecision { namespace backends { // // Start with non-trivial cpp_int's: // -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value, bool>::type @@ -28,7 +28,7 @@ eval_eq(const cpp_int_backend& a { return (a.sign() == b.sign()) && (a.size() == b.size()) && std_constexpr::equal(a.limbs(), a.limbs() + a.size(), b.limbs()); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value && !is_trivial_cpp_int >::value, bool>::type @@ -36,7 +36,7 @@ eval_eq(const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value, bool>::type @@ -44,7 +44,7 @@ eval_eq(const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value, bool>::type @@ -52,7 +52,7 @@ eval_eq(const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value, bool>::type @@ -60,7 +60,7 @@ eval_eq(const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value, bool>::type @@ -69,7 +69,7 @@ eval_eq(const cpp_int_backend(b)) : eval_eq(a, static_cast(b)); // Use bit pattern of b for comparison } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value, bool>::type @@ -81,7 +81,7 @@ eval_lt(const cpp_int_backend +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value, bool>::type @@ -103,7 +103,7 @@ eval_lt(const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value, bool>::type @@ -113,7 +113,7 @@ eval_lt(const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value, bool>::type @@ -122,7 +122,7 @@ eval_lt(const cpp_int_backend(b)); // Use bit pattern of b for comparison } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value, bool>::type @@ -134,7 +134,7 @@ eval_gt(const cpp_int_backend b; } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value, bool>::type @@ -158,7 +158,7 @@ eval_gt(const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value, bool>::type @@ -168,7 +168,7 @@ eval_gt(const cpp_int_backend b; } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value, bool>::type @@ -179,7 +179,7 @@ eval_gt(const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value, bool>::value @@ -187,7 +187,7 @@ eval_eq(const cpp_int_backend { return (a.sign() == b.sign()) && (*a.limbs() == *b.limbs()); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value, bool>::value @@ -195,7 +195,7 @@ eval_eq(const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< boost::multiprecision::detail::is_unsigned::value && is_trivial_cpp_int >::value, bool>::type @@ -203,7 +203,7 @@ eval_eq(const cpp_int_backend { return !a.sign() && (*a.limbs() == b); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< boost::multiprecision::detail::is_signed::value && boost::multiprecision::detail::is_integral::value && is_trivial_cpp_int >::value, bool>::type @@ -211,7 +211,7 @@ eval_eq(const cpp_int_backend { return (a.sign() == (b < 0)) && (*a.limbs() == boost::multiprecision::detail::unsigned_abs(b)); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< boost::multiprecision::detail::is_unsigned::value && is_trivial_cpp_int >::value, bool>::type @@ -219,7 +219,7 @@ eval_eq(const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< boost::multiprecision::detail::is_signed::value && boost::multiprecision::detail::is_integral::value && is_trivial_cpp_int >::value, bool>::type @@ -237,7 +237,7 @@ eval_eq(const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value, bool>::type @@ -247,7 +247,7 @@ eval_lt(const cpp_int_backend return a.sign(); return a.sign() ? *a.limbs() > *b.limbs() : *a.limbs() < *b.limbs(); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value, bool>::type @@ -255,7 +255,7 @@ eval_lt(const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< boost::multiprecision::detail::is_unsigned::value && is_trivial_cpp_int >::value, bool>::type @@ -265,7 +265,7 @@ eval_lt(const cpp_int_backend return true; return *a.limbs() < b; } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< boost::multiprecision::detail::is_signed::value && boost::multiprecision::detail::is_integral::value && is_trivial_cpp_int >::value, bool>::type @@ -275,7 +275,7 @@ eval_lt(const cpp_int_backend return a.sign(); return a.sign() ? (*a.limbs() > boost::multiprecision::detail::unsigned_abs(b)) : (*a.limbs() < boost::multiprecision::detail::unsigned_abs(b)); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< boost::multiprecision::detail::is_unsigned::value && is_trivial_cpp_int >::value, bool>::type @@ -283,7 +283,7 @@ eval_lt(const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< boost::multiprecision::detail::is_signed::value && boost::multiprecision::detail::is_integral::value && is_trivial_cpp_int >::value, bool>::type @@ -301,7 +301,7 @@ eval_lt(const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value, bool>::type @@ -311,7 +311,7 @@ eval_gt(const cpp_int_backend return !a.sign(); return a.sign() ? *a.limbs() < *b.limbs() : *a.limbs() > *b.limbs(); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value, bool>::type @@ -319,7 +319,7 @@ eval_gt(const cpp_int_backend *b.limbs(); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< boost::multiprecision::detail::is_unsigned::value && is_trivial_cpp_int >::value, bool>::type @@ -329,7 +329,7 @@ eval_gt(const cpp_int_backend return false; return *a.limbs() > b; } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< boost::multiprecision::detail::is_signed::value && boost::multiprecision::detail::is_integral::value && is_trivial_cpp_int >::value, bool>::type @@ -339,7 +339,7 @@ eval_gt(const cpp_int_backend return !a.sign(); return a.sign() ? (*a.limbs() < boost::multiprecision::detail::unsigned_abs(b)) : (*a.limbs() > boost::multiprecision::detail::unsigned_abs(b)); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< boost::multiprecision::detail::is_unsigned::value && is_trivial_cpp_int >::value, bool>::type @@ -347,7 +347,7 @@ eval_gt(const cpp_int_backend b; } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< boost::multiprecision::detail::is_signed::value && boost::multiprecision::detail::is_integral::value && is_trivial_cpp_int >::value, bool>::type diff --git a/include/boost/multiprecision/cpp_int/cpp_int_config.hpp b/include/boost/multiprecision/cpp_int/cpp_int_config.hpp index 4dcc5f0f..bc5f33fc 100644 --- a/include/boost/multiprecision/cpp_int/cpp_int_config.hpp +++ b/include/boost/multiprecision/cpp_int/cpp_int_config.hpp @@ -28,7 +28,7 @@ namespace detail { // as possible. // -template +template struct int_t { using exact = typename std::conditional +template struct uint_t { using exact = typename std::conditional +template struct largest_signed_type { using type = typename std::conditional< @@ -85,7 +85,7 @@ struct largest_signed_type typename int_t::exact>::type>::type>::type; }; -template +template struct largest_unsigned_type { using type = typename std::conditional< @@ -111,7 +111,7 @@ using signed_double_limb_type = boost::multiprecision::int128_type; constexpr const limb_type max_block_10 = 1000000000000000000uLL; constexpr const limb_type digits_per_block_10 = 18; -inline BOOST_MP_CXX14_CONSTEXPR limb_type block_multiplier(unsigned count) +inline BOOST_MP_CXX14_CONSTEXPR limb_type block_multiplier(std::size_t count) { constexpr const limb_type values[digits_per_block_10] = {10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, 10000000000000000, 100000000000000000, 1000000000000000000}; BOOST_MP_ASSERT(count < digits_per_block_10); @@ -130,7 +130,7 @@ using signed_double_limb_type = detail::largest_signed_type<64>::type ; constexpr const limb_type max_block_10 = 1000000000; constexpr const limb_type digits_per_block_10 = 9; -inline limb_type block_multiplier(unsigned count) +inline limb_type block_multiplier(std::size_t count) { constexpr const limb_type values[digits_per_block_10] = {10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}; BOOST_MP_ASSERT(count < digits_per_block_10); @@ -139,7 +139,7 @@ inline limb_type block_multiplier(unsigned count) #endif -constexpr const unsigned bits_per_limb = sizeof(limb_type) * CHAR_BIT; +constexpr const std::size_t bits_per_limb = sizeof(limb_type) * CHAR_BIT; template inline BOOST_MP_CXX14_CONSTEXPR void minmax(const T& a, const T& b, T& aa, T& bb) diff --git a/include/boost/multiprecision/cpp_int/divide.hpp b/include/boost/multiprecision/cpp_int/divide.hpp index 473c5eba..4759c3de 100644 --- a/include/boost/multiprecision/cpp_int/divide.hpp +++ b/include/boost/multiprecision/cpp_int/divide.hpp @@ -64,7 +64,7 @@ BOOST_MP_CXX14_CONSTEXPR void divide_unsigned_helper( // // Find the most significant words of numerator and denominator. // - limb_type y_order = y.size() - 1; + std::size_t y_order = y.size() - 1; if (y_order == 0) { @@ -80,7 +80,7 @@ BOOST_MP_CXX14_CONSTEXPR void divide_unsigned_helper( typename CppInt2::const_limb_pointer px = x.limbs(); typename CppInt3::const_limb_pointer py = y.limbs(); - limb_type r_order = x.size() - 1; + std::size_t r_order = x.size() - 1; if ((r_order == 0) && (*px == 0)) { // x is zero, so is the result: @@ -145,7 +145,7 @@ BOOST_MP_CXX14_CONSTEXPR void divide_unsigned_helper( if (result) { pr = result->limbs(); - for (unsigned i = 1; i < 1 + r_order - y_order; ++i) + for (std::size_t i = 1; i < 1 + r_order - y_order; ++i) pr[i] = 0; } bool first_pass = true; @@ -183,7 +183,7 @@ BOOST_MP_CXX14_CONSTEXPR void divide_unsigned_helper( // // Update result: // - limb_type shift = r_order - y_order; + std::size_t shift = r_order - y_order; if (result) { if (r_neg) @@ -194,7 +194,7 @@ BOOST_MP_CXX14_CONSTEXPR void divide_unsigned_helper( { t.resize(shift + 1, shift + 1); t.limbs()[shift] = guess; - for (unsigned i = 0; i < shift; ++i) + for (std::size_t i = 0; i < shift; ++i) t.limbs()[i] = 0; eval_subtract(*result, t); } @@ -205,7 +205,7 @@ BOOST_MP_CXX14_CONSTEXPR void divide_unsigned_helper( { t.resize(shift + 1, shift + 1); t.limbs()[shift] = guess; - for (unsigned i = 0; i < shift; ++i) + for (std::size_t i = 0; i < shift; ++i) t.limbs()[i] = 0; eval_add(*result, t); } @@ -218,9 +218,9 @@ BOOST_MP_CXX14_CONSTEXPR void divide_unsigned_helper( t.resize(y.size() + shift + 1, y.size() + shift); bool truncated_t = (t.size() != y.size() + shift + 1); typename CppInt1::limb_pointer pt = t.limbs(); - for (unsigned i = 0; i < shift; ++i) + for (std::size_t i = 0; i < shift; ++i) pt[i] = 0; - for (unsigned i = 0; i < y.size(); ++i) + for (std::size_t i = 0; i < y.size(); ++i) { carry += static_cast(py[i]) * static_cast(guess); #ifdef __MSVC_RUNTIME_CHECKS @@ -253,7 +253,7 @@ BOOST_MP_CXX14_CONSTEXPR void divide_unsigned_helper( // Simplest way is to get 2^n - r by complementing // r, then add t to it. Note that we can't call eval_complement // in case this is a signed checked type: - for (unsigned i = 0; i <= r_order; ++i) + for (std::size_t i = 0; i <= r_order; ++i) r.limbs()[i] = ~prem[i]; r.normalize(); eval_increment(r); @@ -345,7 +345,7 @@ BOOST_MP_CXX14_CONSTEXPR void divide_unsigned_helper( // // Find the most significant word of numerator. // - limb_type r_order = x.size() - 1; + std::size_t r_order = x.size() - 1; // // Set remainder and result to their initial values: @@ -453,7 +453,7 @@ BOOST_MP_CXX14_CONSTEXPR void divide_unsigned_helper( BOOST_MP_ASSERT(r.compare(y) < 0); // remainder must be less than the divisor or our code has failed } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value && !is_trivial_cpp_int >::value>::type eval_divide( cpp_int_backend& result, @@ -466,7 +466,7 @@ eval_divide( result.sign(s); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_divide( cpp_int_backend& result, @@ -479,7 +479,7 @@ eval_divide( result.sign(s); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_divide( cpp_int_backend& result, @@ -492,7 +492,7 @@ eval_divide( result.sign(s); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_divide( cpp_int_backend& result, @@ -503,7 +503,7 @@ eval_divide( eval_divide(result, a, b); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_divide( cpp_int_backend& result, @@ -514,7 +514,7 @@ eval_divide( eval_divide(result, a, b); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_divide( cpp_int_backend& result, @@ -525,7 +525,7 @@ eval_divide( eval_divide(result, a, b); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value && !is_trivial_cpp_int >::value>::type eval_modulus( cpp_int_backend& result, @@ -540,18 +540,18 @@ eval_modulus( result.sign(s); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_modulus( cpp_int_backend& result, const cpp_int_backend& a, const limb_type mod) { - const int n = a.size(); + const std::ptrdiff_t n = a.size(); const double_limb_type two_n_mod = static_cast(1u) + (~static_cast(0u) - mod) % mod; limb_type res = a.limbs()[n - 1] % mod; - for (int i = n - 2; i >= 0; --i) + for (std::ptrdiff_t i = n - 2; i >= 0; --i) res = (res * two_n_mod + a.limbs()[i]) % mod; // // We must not modify result until here in case @@ -562,7 +562,7 @@ eval_modulus( result.sign(a.sign()); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_modulus( cpp_int_backend& result, @@ -574,7 +574,7 @@ eval_modulus( result.sign(a.sign()); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_modulus( cpp_int_backend& result, @@ -585,7 +585,7 @@ eval_modulus( eval_modulus(result, a, b); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_modulus( cpp_int_backend& result, @@ -595,7 +595,7 @@ eval_modulus( eval_modulus(result, result, b); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_modulus( cpp_int_backend& result, @@ -608,7 +608,7 @@ eval_modulus( // // Over again for trivial cpp_int's: // -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && (is_signed_number >::value || is_signed_number >::value)>::type eval_divide( @@ -621,7 +621,7 @@ eval_divide( result.sign(result.sign() != o.sign()); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && is_unsigned_number >::value && is_unsigned_number >::value>::type eval_divide( @@ -633,7 +633,7 @@ eval_divide( *result.limbs() /= *o.limbs(); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value>::type eval_modulus( diff --git a/include/boost/multiprecision/cpp_int/import_export.hpp b/include/boost/multiprecision/cpp_int/import_export.hpp index 8b72d76a..10f2f498 100644 --- a/include/boost/multiprecision/cpp_int/import_export.hpp +++ b/include/boost/multiprecision/cpp_int/import_export.hpp @@ -16,10 +16,10 @@ namespace multiprecision { namespace detail { template -void assign_bits(Backend& val, Unsigned bits, unsigned bit_location, unsigned chunk_bits, const std::integral_constant& tag) +void assign_bits(Backend& val, Unsigned bits, std::size_t bit_location, std::size_t chunk_bits, const std::integral_constant& tag) { - unsigned limb = bit_location / (sizeof(limb_type) * CHAR_BIT); - unsigned shift = bit_location % (sizeof(limb_type) * CHAR_BIT); + std::size_t limb = bit_location / (sizeof(limb_type) * CHAR_BIT); + std::size_t shift = bit_location % (sizeof(limb_type) * CHAR_BIT); limb_type mask = chunk_bits >= sizeof(limb_type) * CHAR_BIT ? ~static_cast(0u) : (static_cast(1u) << chunk_bits) - 1; @@ -46,7 +46,7 @@ void assign_bits(Backend& val, Unsigned bits, unsigned bit_location, unsigned ch } } template -void assign_bits(Backend& val, Unsigned bits, unsigned bit_location, unsigned chunk_bits, const std::integral_constant&) +void assign_bits(Backend& val, Unsigned bits, std::size_t bit_location, std::size_t chunk_bits, const std::integral_constant&) { using local_limb_type = typename Backend::local_limb_type; // @@ -69,28 +69,28 @@ void assign_bits(Backend& val, Unsigned bits, unsigned bit_location, unsigned ch } } -template -inline void resize_to_bit_size(cpp_int_backend& newval, unsigned bits, const std::integral_constant&) +template +inline void resize_to_bit_size(cpp_int_backend& newval, std::size_t bits, const std::integral_constant&) { - unsigned limb_count = static_cast(bits / (sizeof(limb_type) * CHAR_BIT)); + std::size_t limb_count = static_cast(bits / (sizeof(limb_type) * CHAR_BIT)); if (bits % (sizeof(limb_type) * CHAR_BIT)) ++limb_count; - constexpr const unsigned max_limbs = MaxBits ? MaxBits / (CHAR_BIT * sizeof(limb_type)) + ((MaxBits % (CHAR_BIT * sizeof(limb_type))) ? 1 : 0) : (std::numeric_limits::max)(); + constexpr const std::size_t max_limbs = MaxBits ? MaxBits / (CHAR_BIT * sizeof(limb_type)) + ((MaxBits % (CHAR_BIT * sizeof(limb_type))) ? 1 : 0) : (std::numeric_limits::max)(); if (limb_count > max_limbs) limb_count = max_limbs; newval.resize(limb_count, limb_count); std::memset(newval.limbs(), 0, newval.size() * sizeof(limb_type)); } -template +template inline void resize_to_bit_size(cpp_int_backend& newval, unsigned, const std::integral_constant&) { *newval.limbs() = 0; } -template +template number, ExpressionTemplates>& import_bits_generic( - number, ExpressionTemplates>& val, Iterator i, Iterator j, unsigned chunk_size = 0, bool msv_first = true) + number, ExpressionTemplates>& val, Iterator i, Iterator j, std::size_t chunk_size = 0, bool msv_first = true) { typename number, ExpressionTemplates>::backend_type newval; @@ -113,7 +113,7 @@ import_bits_generic( while (i != j) { - detail::assign_bits(newval, static_cast(*i), static_cast(bit_location), chunk_size, tag_type()); + detail::assign_bits(newval, static_cast(*i), static_cast(bit_location), chunk_size, tag_type()); ++i; bit_location += bit_location_change; } @@ -124,10 +124,10 @@ import_bits_generic( return val; } -template +template inline typename std::enable_if< !boost::multiprecision::backends::is_trivial_cpp_int >::value, number, ExpressionTemplates>&>::type import_bits_fast( - number, ExpressionTemplates>& val, T* i, T* j, unsigned chunk_size = 0) + number, ExpressionTemplates>& val, T* i, T* j, std::size_t chunk_size = 0) { std::size_t byte_len = (j - i) * (chunk_size ? chunk_size / CHAR_BIT : sizeof(*i)); std::size_t limb_len = byte_len / sizeof(limb_type); @@ -140,10 +140,10 @@ import_bits_fast( result.normalize(); // In case data has leading zeros. return val; } -template +template inline typename std::enable_if >::value, number, ExpressionTemplates>&>::type import_bits_fast( - number, ExpressionTemplates>& val, T* i, T* j, unsigned chunk_size = 0) + number, ExpressionTemplates>& val, T* i, T* j, std::size_t chunk_size = 0) { cpp_int_backend& result = val.backend(); std::size_t byte_len = (j - i) * (chunk_size ? chunk_size / CHAR_BIT : sizeof(*i)); @@ -158,18 +158,18 @@ import_bits_fast( } } // namespace detail -template +template inline number, ExpressionTemplates>& import_bits( - number, ExpressionTemplates>& val, Iterator i, Iterator j, unsigned chunk_size = 0, bool msv_first = true) + number, ExpressionTemplates>& val, Iterator i, Iterator j, std::size_t chunk_size = 0, bool msv_first = true) { return detail::import_bits_generic(val, i, j, chunk_size, msv_first); } -template +template inline number, ExpressionTemplates>& import_bits( - number, ExpressionTemplates>& val, T* i, T* j, unsigned chunk_size = 0, bool msv_first = true) + number, ExpressionTemplates>& val, T* i, T* j, std::size_t chunk_size = 0, bool msv_first = true) { #if BOOST_MP_ENDIAN_LITTLE_BYTE if (((chunk_size % CHAR_BIT) == 0) && !msv_first) @@ -181,10 +181,10 @@ import_bits( namespace detail { template -std::uintmax_t extract_bits(const Backend& val, unsigned location, unsigned count, const std::integral_constant& tag) +std::uintmax_t extract_bits(const Backend& val, std::size_t location, std::size_t count, const std::integral_constant& tag) { - unsigned limb = location / (sizeof(limb_type) * CHAR_BIT); - unsigned shift = location % (sizeof(limb_type) * CHAR_BIT); + std::size_t limb = location / (sizeof(limb_type) * CHAR_BIT); + std::size_t shift = location % (sizeof(limb_type) * CHAR_BIT); std::uintmax_t result = 0; std::uintmax_t mask = count == std::numeric_limits::digits ? ~static_cast(0) : (static_cast(1u) << count) - 1; if (count > (sizeof(limb_type) * CHAR_BIT - shift)) @@ -198,7 +198,7 @@ std::uintmax_t extract_bits(const Backend& val, unsigned location, unsigned coun } template -inline std::uintmax_t extract_bits(const Backend& val, unsigned location, unsigned count, const std::integral_constant&) +inline std::uintmax_t extract_bits(const Backend& val, std::size_t location, std::size_t count, const std::integral_constant&) { typename Backend::local_limb_type result = *val.limbs(); typename Backend::local_limb_type mask = count >= std::numeric_limits::digits ? ~static_cast(0) : (static_cast(1u) << count) - 1; @@ -207,9 +207,9 @@ inline std::uintmax_t extract_bits(const Backend& val, unsigned location, unsign } // namespace detail -template +template OutputIterator export_bits( - const number, ExpressionTemplates>& val, OutputIterator out, unsigned chunk_size, bool msv_first = true) + const number, ExpressionTemplates>& val, OutputIterator out, std::size_t chunk_size, bool msv_first = true) { #ifdef _MSC_VER #pragma warning(push) @@ -222,13 +222,13 @@ OutputIterator export_bits( ++out; return out; } - unsigned bitcount = boost::multiprecision::backends::eval_msb_imp(val.backend()) + 1; - unsigned chunks = bitcount / chunk_size; + std::size_t bitcount = boost::multiprecision::backends::eval_msb_imp(val.backend()) + 1; + std::size_t chunks = bitcount / chunk_size; if (bitcount % chunk_size) ++chunks; - int bit_location = msv_first ? bitcount - chunk_size : 0; - int bit_step = msv_first ? -static_cast(chunk_size) : chunk_size; + std::ptrdiff_t bit_location = msv_first ? bitcount - chunk_size : 0; + std::ptrdiff_t bit_step = msv_first ? -static_cast(chunk_size) : chunk_size; while (bit_location % bit_step) ++bit_location; diff --git a/include/boost/multiprecision/cpp_int/limits.hpp b/include/boost/multiprecision/cpp_int/limits.hpp index 7c48a36b..01a18d08 100644 --- a/include/boost/multiprecision/cpp_int/limits.hpp +++ b/include/boost/multiprecision/cpp_int/limits.hpp @@ -19,7 +19,7 @@ namespace detail { #pragma warning(disable : 4307) #endif -template +template inline BOOST_CXX14_CONSTEXPR_IF_DETECTION boost::multiprecision::number, ExpressionTemplates> get_min(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { @@ -35,7 +35,7 @@ get_min(const std::integral_constant&, const std::integral_constant< return val; } -template +template inline boost::multiprecision::number, ExpressionTemplates> get_min(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { @@ -46,7 +46,7 @@ get_min(const std::integral_constant&, const std::integral_constant< return val; } -template +template inline BOOST_CXX14_CONSTEXPR_IF_DETECTION boost::multiprecision::number, ExpressionTemplates> get_min(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { @@ -60,16 +60,16 @@ get_min(const std::integral_constant&, const std::integral_constant< return val; } -template +template inline boost::multiprecision::number, ExpressionTemplates> get_min(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { - // Bounded and unsigned with allocator (no constexpr): + // Bounded and std::size_t with allocator (no constexpr): static const boost::multiprecision::number, ExpressionTemplates> val(0u); return val; } -template +template inline boost::multiprecision::number, ExpressionTemplates> get_min(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { @@ -79,7 +79,7 @@ get_min(const std::integral_constant&, const std::integral_constant return val; } -template +template inline boost::multiprecision::number, ExpressionTemplates> get_min(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { @@ -88,7 +88,7 @@ get_min(const std::integral_constant&, const std::integral_constant return val; } -template +template inline BOOST_CXX14_CONSTEXPR_IF_DETECTION boost::multiprecision::number, ExpressionTemplates> get_max(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { @@ -104,7 +104,7 @@ get_max(const std::integral_constant&, const std::integral_constant< return val; } -template +template inline boost::multiprecision::number, ExpressionTemplates> get_max(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { @@ -115,7 +115,7 @@ get_max(const std::integral_constant&, const std::integral_constant< return val; } -template +template inline BOOST_CXX14_CONSTEXPR_IF_DETECTION boost::multiprecision::number, ExpressionTemplates> get_max(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { @@ -131,7 +131,7 @@ get_max(const std::integral_constant&, const std::integral_constant< return val; } -template +template inline boost::multiprecision::number, ExpressionTemplates> get_max(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { @@ -142,7 +142,7 @@ get_max(const std::integral_constant&, const std::integral_constant< return val; } -template +template inline boost::multiprecision::number, ExpressionTemplates> get_max(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { @@ -152,7 +152,7 @@ get_max(const std::integral_constant&, const std::integral_constant return val; } -template +template inline boost::multiprecision::number, ExpressionTemplates> get_max(const std::integral_constant&, const std::integral_constant&, const std::integral_constant&) { @@ -163,7 +163,7 @@ get_max(const std::integral_constant&, const std::integral_constant } // namespace detail -template +template class numeric_limits, ExpressionTemplates> > { using backend_type = boost::multiprecision::cpp_int_backend; @@ -214,49 +214,49 @@ class numeric_limits +template constexpr int numeric_limits, ExpressionTemplates> >::digits; -template +template constexpr int numeric_limits, ExpressionTemplates> >::digits10; -template +template constexpr int numeric_limits, ExpressionTemplates> >::max_digits10; -template +template constexpr bool numeric_limits, ExpressionTemplates> >::is_signed; -template +template constexpr bool numeric_limits, ExpressionTemplates> >::is_integer; -template +template constexpr bool numeric_limits, ExpressionTemplates> >::is_exact; -template +template constexpr int numeric_limits, ExpressionTemplates> >::radix; -template +template constexpr int numeric_limits, ExpressionTemplates> >::min_exponent; -template +template constexpr int numeric_limits, ExpressionTemplates> >::min_exponent10; -template +template constexpr int numeric_limits, ExpressionTemplates> >::max_exponent; -template +template constexpr int numeric_limits, ExpressionTemplates> >::max_exponent10; -template +template constexpr bool numeric_limits, ExpressionTemplates> >::has_infinity; -template +template constexpr bool numeric_limits, ExpressionTemplates> >::has_quiet_NaN; -template +template constexpr bool numeric_limits, ExpressionTemplates> >::has_signaling_NaN; -template +template constexpr float_denorm_style numeric_limits, ExpressionTemplates> >::has_denorm; -template +template constexpr bool numeric_limits, ExpressionTemplates> >::has_denorm_loss; -template +template constexpr bool numeric_limits, ExpressionTemplates> >::is_iec559; -template +template constexpr bool numeric_limits, ExpressionTemplates> >::is_bounded; -template +template constexpr bool numeric_limits, ExpressionTemplates> >::is_modulo; -template +template constexpr bool numeric_limits, ExpressionTemplates> >::traps; -template +template constexpr bool numeric_limits, ExpressionTemplates> >::tinyness_before; -template +template constexpr float_round_style numeric_limits, ExpressionTemplates> >::round_style; #ifdef _MSC_VER diff --git a/include/boost/multiprecision/cpp_int/literals.hpp b/include/boost/multiprecision/cpp_int/literals.hpp index 957677ad..5c4ba72e 100644 --- a/include/boost/multiprecision/cpp_int/literals.hpp +++ b/include/boost/multiprecision/cpp_int/literals.hpp @@ -137,8 +137,8 @@ struct combine_value_to_pack, value> template struct pack_values { - static constexpr unsigned chars_per_limb = sizeof(limb_type) * CHAR_BIT / 4; - static constexpr unsigned shift = ((sizeof...(CHARS)) % chars_per_limb) * 4; + static constexpr std::size_t chars_per_limb = sizeof(limb_type) * CHAR_BIT / 4; + static constexpr std::size_t shift = ((sizeof...(CHARS)) % chars_per_limb) * 4; static constexpr limb_type value_to_add = shift ? hex_value::value << shift : hex_value::value; using recursive_packed_type = typename pack_values::type ; @@ -275,13 +275,13 @@ BOOST_MP_DEFINE_SIZED_CPP_INT_LITERAL(1024) // // Overload unary minus operator for constexpr use: // -template +template constexpr number, et_off> operator-(const number, et_off>& a) { return cpp_int_backend(a.backend(), boost::multiprecision::literals::detail::make_negate_tag()); } -template +template constexpr number, et_off> operator-(number, et_off>&& a) { diff --git a/include/boost/multiprecision/cpp_int/misc.hpp b/include/boost/multiprecision/cpp_int/misc.hpp index 354e436e..03e80a91 100644 --- a/include/boost/multiprecision/cpp_int/misc.hpp +++ b/include/boost/multiprecision/cpp_int/misc.hpp @@ -95,7 +95,7 @@ inline BOOST_MP_CXX14_CONSTEXPR Integer negate_integer(Integer i, const std::int return ~(i - 1); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value && !is_trivial_cpp_int >::value, void>::type eval_convert_to(R* result, const cpp_int_backend& backend) { @@ -119,8 +119,8 @@ eval_convert_to(R* result, const cpp_int_backend(backend.limbs()[0]); - unsigned shift = cpp_int_backend::limb_bits; - unsigned i = 1; + std::size_t shift = cpp_int_backend::limb_bits; + std::size_t i = 1; BOOST_IF_CONSTEXPR(numeric_limits_workaround::digits > cpp_int_backend::limb_bits) { while ((i < backend.size()) && (shift < static_cast(numeric_limits_workaround::digits - cpp_int_backend::limb_bits))) @@ -169,7 +169,7 @@ eval_convert_to(R* result, const cpp_int_backend +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value && !is_trivial_cpp_int >::value, void>::type eval_convert_to(R* result, const cpp_int_backend& backend) noexcept(boost::multiprecision::detail::is_arithmetic::value) { @@ -192,7 +192,7 @@ eval_convert_to(R* result, const cpp_int_backend::limb_bits * index; while (bits_to_keep > 0) { - if (bits_to_keep < cpp_int_backend::limb_bits) + if (bits_to_keep < (std::ptrdiff_t)cpp_int_backend::limb_bits) { if(index != backend.size() - 1) mask <<= cpp_int_backend::limb_bits - bits_to_keep; @@ -216,18 +216,18 @@ eval_convert_to(R* result, const cpp_int_backend::digits; if (eval_bit_test(backend, (unsigned)bits)) { - if ((eval_lsb_imp(backend) < bits) || eval_bit_test(backend, (unsigned)(bits + 1))) + if ((eval_lsb_imp(backend) < (std::size_t)bits) || eval_bit_test(backend, (std::size_t)(bits + 1))) *result = boost::math::float_next(*result); } } else { typename cpp_int_backend::const_limb_pointer p = backend.limbs(); - unsigned shift = cpp_int_backend::limb_bits; + std::size_t shift = cpp_int_backend::limb_bits; *result = static_cast(*p); - for (unsigned i = 1; i < backend.size(); ++i) + for (std::size_t i = 1; i < backend.size(); ++i) { - *result += static_cast(std::ldexp(static_cast(p[i]), shift)); + *result += static_cast(std::ldexp(static_cast(p[i]), (int)shift)); shift += cpp_int_backend::limb_bits; } } @@ -235,19 +235,19 @@ eval_convert_to(R* result, const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, bool>::type eval_is_zero(const cpp_int_backend& val) noexcept { return (val.size() == 1) && (val.limbs()[0] == 0); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, int>::type eval_get_sign(const cpp_int_backend& val) noexcept { return eval_is_zero(val) ? 0 : val.sign() ? -1 : 1; } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_abs(cpp_int_backend& result, const cpp_int_backend& val) noexcept((is_non_throwing_cpp_int >::value)) { @@ -258,26 +258,26 @@ eval_abs(cpp_int_backend& r // // Get the location of the least-significant-bit: // -template -inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, unsigned>::type +template +inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, std::size_t>::type eval_lsb_imp(const cpp_int_backend& a) { // // Find the index of the least significant limb that is non-zero: // - unsigned index = 0; + std::size_t index = 0; while (!a.limbs()[index] && (index < a.size())) ++index; // // Find the index of the least significant bit within that limb: // - unsigned result = boost::multiprecision::detail::find_lsb(a.limbs()[index]); + std::size_t result = boost::multiprecision::detail::find_lsb(a.limbs()[index]); return result + index * cpp_int_backend::limb_bits; } -template -inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, unsigned>::type +template +inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, std::size_t>::type eval_lsb(const cpp_int_backend& a) { using default_ops::eval_get_sign; @@ -295,8 +295,8 @@ eval_lsb(const cpp_int_backend -inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, unsigned>::type +template +inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, std::size_t>::type eval_msb_imp(const cpp_int_backend& a) { // @@ -305,8 +305,8 @@ eval_msb_imp(const cpp_int_backend::limb_bits + boost::multiprecision::detail::find_msb(a.limbs()[a.size() - 1]); } -template -inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, unsigned>::type +template +inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, std::size_t>::type eval_msb(const cpp_int_backend& a) { using default_ops::eval_get_sign; @@ -330,12 +330,12 @@ eval_msb(const cpp_int_backend +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, bool>::type -eval_bit_test(const cpp_int_backend& val, unsigned index) noexcept +eval_bit_test(const cpp_int_backend& val, std::size_t index) noexcept { - unsigned offset = index / cpp_int_backend::limb_bits; - unsigned shift = index % cpp_int_backend::limb_bits; + std::size_t offset = index / cpp_int_backend::limb_bits; + std::size_t shift = index % cpp_int_backend::limb_bits; limb_type mask = shift ? limb_type(1u) << shift : limb_type(1u); if (offset >= val.size()) return false; @@ -346,31 +346,31 @@ eval_bit_test(const cpp_int_backend +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type -eval_bit_set(cpp_int_backend& val, unsigned index) +eval_bit_set(cpp_int_backend& val, std::size_t index) { - unsigned offset = index / cpp_int_backend::limb_bits; - unsigned shift = index % cpp_int_backend::limb_bits; + std::size_t offset = index / cpp_int_backend::limb_bits; + std::size_t shift = index % cpp_int_backend::limb_bits; limb_type mask = shift ? limb_type(1u) << shift : limb_type(1u); if (offset >= val.size()) { - unsigned os = val.size(); + std::size_t os = val.size(); val.resize(offset + 1, offset + 1); if (offset >= val.size()) return; // fixed precision overflow - for (unsigned i = os; i <= offset; ++i) + for (std::size_t i = os; i <= offset; ++i) val.limbs()[i] = 0; } val.limbs()[offset] |= mask; } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type -eval_bit_unset(cpp_int_backend& val, unsigned index) noexcept +eval_bit_unset(cpp_int_backend& val, std::size_t index) noexcept { - unsigned offset = index / cpp_int_backend::limb_bits; - unsigned shift = index % cpp_int_backend::limb_bits; + std::size_t offset = index / cpp_int_backend::limb_bits; + std::size_t shift = index % cpp_int_backend::limb_bits; limb_type mask = shift ? limb_type(1u) << shift : limb_type(1u); if (offset >= val.size()) return; @@ -378,27 +378,27 @@ eval_bit_unset(cpp_int_backend +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type -eval_bit_flip(cpp_int_backend& val, unsigned index) +eval_bit_flip(cpp_int_backend& val, std::size_t index) { - unsigned offset = index / cpp_int_backend::limb_bits; - unsigned shift = index % cpp_int_backend::limb_bits; + std::size_t offset = index / cpp_int_backend::limb_bits; + std::size_t shift = index % cpp_int_backend::limb_bits; limb_type mask = shift ? limb_type(1u) << shift : limb_type(1u); if (offset >= val.size()) { - unsigned os = val.size(); + std::size_t os = val.size(); val.resize(offset + 1, offset + 1); if (offset >= val.size()) return; // fixed precision overflow - for (unsigned i = os; i <= offset; ++i) + for (std::size_t i = os; i <= offset; ++i) val.limbs()[i] = 0; } val.limbs()[offset] ^= mask; val.normalize(); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_qr( const cpp_int_backend& x, @@ -411,7 +411,7 @@ eval_qr( r.sign(x.sign()); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_qr( const cpp_int_backend& x, @@ -424,7 +424,7 @@ eval_qr( r.sign(x.sign()); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value>::type eval_qr( const cpp_int_backend& x, U y, @@ -437,7 +437,7 @@ inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value && !is_trivial_cpp_int >::value, Integer>::type eval_integer_modulus(const cpp_int_backend& a, Integer mod) { @@ -445,11 +445,11 @@ eval_integer_modulus(const cpp_int_backend::max)()) { - const int n = a.size(); + const std::ptrdiff_t n = a.size(); const double_limb_type two_n_mod = static_cast(1u) + (~static_cast(0u) - mod) % mod; limb_type res = a.limbs()[n - 1] % mod; - for (int i = n - 2; i >= 0; --i) + for (std::ptrdiff_t i = n - 2; i >= 0; --i) res = static_cast((res * two_n_mod + a.limbs()[i]) % mod); return res; } @@ -462,7 +462,7 @@ eval_integer_modulus(const cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value && boost::multiprecision::detail::is_integral::value && !is_trivial_cpp_int >::value, Integer>::type eval_integer_modulus(const cpp_int_backend& x, Integer val) { @@ -477,7 +477,7 @@ BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR limb_type eval_gcd(limb_type u, li #if __cpp_lib_gcd_lcm >= 201606L return std::gcd(u, v); #else - unsigned shift = boost::multiprecision::detail::find_lsb(u | v); + std::size_t shift = boost::multiprecision::detail::find_lsb(u | v); u >>= boost::multiprecision::detail::find_lsb(u); do { @@ -498,7 +498,7 @@ inline BOOST_MP_CXX14_CONSTEXPR double_limb_type eval_gcd(double_limb_type u, do if (u == 0) return v; - unsigned shift = boost::multiprecision::detail::find_lsb(u | v); + std::size_t shift = boost::multiprecision::detail::find_lsb(u | v); u >>= boost::multiprecision::detail::find_lsb(u); do { @@ -511,7 +511,7 @@ inline BOOST_MP_CXX14_CONSTEXPR double_limb_type eval_gcd(double_limb_type u, do #endif } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_gcd( cpp_int_backend& result, @@ -533,7 +533,7 @@ eval_gcd( result.sign(false); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_gcd( cpp_int_backend& result, @@ -562,7 +562,7 @@ eval_gcd( result = res; result.sign(false); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_gcd( cpp_int_backend& result, @@ -574,7 +574,7 @@ eval_gcd( // // These 2 overloads take care of gcd against an (unsigned) short etc: // -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value && (sizeof(Integer) <= sizeof(limb_type)) && !is_trivial_cpp_int >::value>::type eval_gcd( cpp_int_backend& result, @@ -583,7 +583,7 @@ eval_gcd( { eval_gcd(result, a, static_cast(v)); } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value && boost::multiprecision::detail::is_integral::value && (sizeof(Integer) <= sizeof(limb_type)) && !is_trivial_cpp_int >::value>::type eval_gcd( cpp_int_backend& result, @@ -626,13 +626,13 @@ eval_gcd( // When double_limb_type is a native integer type then we should just use it and not worry about the consequences. // This can eliminate approximately a full limb with each call. // -template -void eval_gcd_lehmer(cpp_int_backend& U, cpp_int_backend& V, unsigned lu, Storage& storage) +template +void eval_gcd_lehmer(cpp_int_backend& U, cpp_int_backend& V, std::size_t lu, Storage& storage) { // // Extract the leading 2 * bits_per_limb bits from U and V: // - unsigned h = lu % bits_per_limb; + std::size_t h = lu % bits_per_limb; double_limb_type u = (static_cast((U.limbs()[U.size() - 1])) << bits_per_limb) | U.limbs()[U.size() - 2]; double_limb_type v = (static_cast((V.size() < U.size() ? 0 : V.limbs()[V.size() - 1])) << bits_per_limb) | V.limbs()[U.size() - 2]; if (h) @@ -654,7 +654,7 @@ void eval_gcd_lehmer(cpp_int_backend t1(storage, ts), t2(storage, ts), t3(storage, ts); eval_multiply(t1, U, static_cast(x[0])); eval_multiply(t2, V, static_cast(y[0])); @@ -772,9 +772,9 @@ void eval_gcd_lehmer(cpp_int_backend -void eval_gcd_lehmer(cpp_int_backend& U, cpp_int_backend& V, unsigned lu, Storage& storage) +template +void eval_gcd_lehmer(cpp_int_backend& U, cpp_int_backend& V, std::size_t lu, Storage& storage) { // // Extract the leading 2*bits_per_limb bits from U and V: // - unsigned h = lu % bits_per_limb; + std::size_t h = lu % bits_per_limb; double_limb_type u, v; if (h) { @@ -862,7 +862,7 @@ void eval_gcd_lehmer(cpp_int_backend t1(storage, ts), t2(storage, ts), t3(storage, ts); eval_multiply(t1, U, x[0]); eval_multiply(t2, V, y[0]); @@ -1039,9 +1039,9 @@ void eval_gcd_lehmer(cpp_int_backend +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_gcd( cpp_int_backend& result, @@ -1094,7 +1094,7 @@ eval_gcd( eval_gcd(result, a, *b.limbs()); return; } - unsigned temp_size = (std::max)(a.size(), b.size()) + 1; + std::size_t temp_size = (std::max)(a.size(), b.size()) + 1; typename cpp_int_backend::scoped_shared_storage storage(a, temp_size * 6); cpp_int_backend U(storage, temp_size); @@ -1128,9 +1128,9 @@ eval_gcd( // // Remove common factors of 2: // - unsigned us = eval_lsb(U); - unsigned vs = eval_lsb(V); - int shift = (std::min)(us, vs); + std::size_t us = eval_lsb(U); + std::size_t vs = eval_lsb(V); + std::size_t shift = (std::min)(us, vs); if (us) eval_right_shift(U, us); if (vs) @@ -1158,8 +1158,8 @@ eval_gcd( } break; } - unsigned lu = eval_msb(U) + 1; - unsigned lv = eval_msb(V) + 1; + std::size_t lu = eval_msb(U) + 1; + std::size_t lv = eval_msb(V) + 1; #ifndef BOOST_MP_NO_CONSTEXPR_DETECTION if (!BOOST_MP_IS_CONST_EVALUATED(lu) && (lu - lv <= bits_per_limb / 2)) #else @@ -1182,7 +1182,7 @@ eval_gcd( // // Now again for trivial backends: // -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_gcd(cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) noexcept { @@ -1190,7 +1190,7 @@ eval_gcd(cpp_int_backend& r result.sign(false); } // This one is only enabled for unchecked cpp_int's, for checked int's we need the checking in the default version: -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && (Checked1 == unchecked)>::type eval_lcm(cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) noexcept((is_non_throwing_cpp_int >::value)) { @@ -1211,7 +1211,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void conversion_overflow(const std::integral_con // See: https://bugs.llvm.org/show_bug.cgi?id=48941 // These workarounds pass everything through an intermediate uint64_t. // -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_signed_number >::value && std::is_same::local_limb_type, double_limb_type>::value>::type eval_convert_to(float* result, const cpp_int_backend& val) @@ -1222,7 +1222,7 @@ eval_convert_to(float* result, const cpp_int_backend +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_signed_number >::value && std::is_same::local_limb_type, double_limb_type>::value>::type eval_convert_to(double* result, const cpp_int_backend& val) @@ -1233,7 +1233,7 @@ eval_convert_to(double* result, const cpp_int_backend +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_signed_number >::value && std::is_same::local_limb_type, double_limb_type>::value>::type eval_convert_to(long double* result, const cpp_int_backend& val) @@ -1246,7 +1246,7 @@ eval_convert_to(long double* result, const cpp_int_backend +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_signed_number >::value && std::is_convertible::local_limb_type, R>::value>::type eval_convert_to(R* result, const cpp_int_backend& val) @@ -1290,7 +1290,7 @@ eval_convert_to(R* result, const cpp_int_backend +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_unsigned_number >::value && std::is_convertible::local_limb_type, R>::value>::type eval_convert_to(R* result, const cpp_int_backend& val) @@ -1310,8 +1310,8 @@ eval_convert_to(R* result, const cpp_int_backend(*val.limbs()); } -template -inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, unsigned>::type +template +inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, std::size_t>::type eval_lsb(const cpp_int_backend& a) { using default_ops::eval_get_sign; @@ -1329,8 +1329,8 @@ eval_lsb(const cpp_int_backend -inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, unsigned>::type +template +inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, std::size_t>::type eval_msb_imp(const cpp_int_backend& a) { // @@ -1339,8 +1339,8 @@ eval_msb_imp(const cpp_int_backend -inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, unsigned>::type +template +inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value, std::size_t>::type eval_msb(const cpp_int_backend& a) { using default_ops::eval_get_sign; @@ -1355,11 +1355,11 @@ eval_msb(const cpp_int_backend +template inline BOOST_MP_CXX14_CONSTEXPR std::size_t hash_value(const cpp_int_backend& val) noexcept { std::size_t result = 0; - for (unsigned i = 0; i < val.size(); ++i) + for (std::size_t i = 0; i < val.size(); ++i) { boost::multiprecision::detail::hash_combine(result, val.limbs()[i]); } diff --git a/include/boost/multiprecision/cpp_int/multiply.hpp b/include/boost/multiprecision/cpp_int/multiply.hpp index a1aa0b8e..1768970e 100644 --- a/include/boost/multiprecision/cpp_int/multiply.hpp +++ b/include/boost/multiprecision/cpp_int/multiply.hpp @@ -25,7 +25,7 @@ namespace boost { namespace multiprecision { namespace backends { // // Multiplication by a single limb: // -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_multiply( cpp_int_backend& result, @@ -56,7 +56,7 @@ eval_multiply( } if (carry) { - unsigned i = result.size(); + std::size_t i = result.size(); result.resize(i + 1, i + 1); if (result.size() > i) result.limbs()[i] = static_cast(carry); @@ -71,11 +71,11 @@ eval_multiply( // for "required" elements could possibly have failed, *and* we have checking enabled. // This will cause an overflow error inside resize(): // -template -inline BOOST_MP_CXX14_CONSTEXPR void resize_for_carry(cpp_int_backend& /*result*/, unsigned /*required*/) {} +template +inline BOOST_MP_CXX14_CONSTEXPR void resize_for_carry(cpp_int_backend& /*result*/, std::size_t /*required*/) {} -template -inline BOOST_MP_CXX14_CONSTEXPR void resize_for_carry(cpp_int_backend& result, unsigned required) +template +inline BOOST_MP_CXX14_CONSTEXPR void resize_for_carry(cpp_int_backend& result, std::size_t required) { if (result.size() < required) result.resize(required, required); @@ -94,7 +94,7 @@ const size_t karatsuba_cutoff = 40; // and full variable precision. Karatsuba really doesn't play nice with fixed-size integers. If necessary // fixed precision integers will get aliased as variable-precision types before this is called. // -template +template inline void multiply_karatsuba( cpp_int_backend& result, const cpp_int_backend& a, @@ -103,8 +103,8 @@ inline void multiply_karatsuba( { using cpp_int_type = cpp_int_backend; - unsigned as = a.size(); - unsigned bs = b.size(); + std::size_t as = a.size(); + std::size_t bs = b.size(); // // Termination condition: if either argument is smaller than karatsuba_cutoff // then schoolboy multiplication will be faster: @@ -117,7 +117,7 @@ inline void multiply_karatsuba( // // Partitioning size: split the larger of a and b into 2 halves // - unsigned n = (as > bs ? as : bs) / 2 + 1; + std::size_t n = (as > bs ? as : bs) / 2 + 1; // // Partition a and b into high and low parts. // ie write a, b as a = a_h * 2^n + a_l, b = b_h * 2^n + b_l @@ -132,7 +132,7 @@ inline void multiply_karatsuba( // * Since we have one high part zero, the arithmetic simplifies considerably, // so should we have a special routine for this? // - unsigned sz = (std::min)(as, n); + std::size_t sz = (std::min)(as, n); const cpp_int_type a_l(a.limbs(), 0, sz); sz = (std::min)(bs, n); @@ -175,13 +175,13 @@ inline void multiply_karatsuba( // that it's worth the extra logic though (and is darn hard to measure // what the "average" case is). // - for (unsigned i = result_low.size(); i < 2 * n; ++i) + for (std::size_t i = result_low.size(); i < 2 * n; ++i) result.limbs()[i] = 0; // // Set the high part of result to a_h * b_h: // multiply_karatsuba(result_high, a_h, b_h, storage); - for (unsigned i = result_high.size() + 2 * n; i < result.size(); ++i) + for (std::size_t i = result_high.size() + 2 * n; i < result.size(); ++i) result.limbs()[i] = 0; // // Now calculate (a_h+a_l)*(b_h+b_l): @@ -214,7 +214,7 @@ inline void multiply_karatsuba( result.normalize(); } -inline unsigned karatsuba_storage_size(unsigned s) +inline std::size_t karatsuba_storage_size(std::size_t s) { // // This estimates how much memory we will need based on @@ -236,17 +236,17 @@ inline unsigned karatsuba_storage_size(unsigned s) // // Normal variable precision case comes first: // -template +template inline typename std::enable_if >::value>::type setup_karatsuba( cpp_int_backend& result, const cpp_int_backend& a, const cpp_int_backend& b) { - unsigned as = a.size(); - unsigned bs = b.size(); - unsigned s = as > bs ? as : bs; - unsigned storage_size = karatsuba_storage_size(s); + std::size_t as = a.size(); + std::size_t bs = b.size(); + std::size_t s = as > bs ? as : bs; + std::size_t storage_size = karatsuba_storage_size(s); if (storage_size < 300) { // @@ -265,7 +265,7 @@ setup_karatsuba( } } -template +template inline typename std::enable_if >::value || is_fixed_precision >::value || is_fixed_precision >::value>::type setup_karatsuba( cpp_int_backend& result, @@ -282,11 +282,11 @@ setup_karatsuba( // using variable_precision_type = cpp_int_backend<0, 0, signed_magnitude, unchecked, std::allocator >; variable_precision_type a_t(a.limbs(), 0, a.size()), b_t(b.limbs(), 0, b.size()); - unsigned as = a.size(); - unsigned bs = b.size(); - unsigned s = as > bs ? as : bs; - unsigned sz = as + bs; - unsigned storage_size = karatsuba_storage_size(s); + std::size_t as = a.size(); + std::size_t bs = b.size(); + std::size_t s = as > bs ? as : bs; + std::size_t sz = as + bs; + std::size_t storage_size = karatsuba_storage_size(s); if (!is_fixed_precision >::value || (sz * sizeof(limb_type) * CHAR_BIT <= MaxBits1)) { @@ -312,7 +312,7 @@ setup_karatsuba( result = t; } } -template +template inline typename std::enable_if >::value && !is_fixed_precision >::value && !is_fixed_precision >::value>::type setup_karatsuba( cpp_int_backend& result, @@ -324,11 +324,11 @@ setup_karatsuba( // using variable_precision_type = cpp_int_backend<0, 0, signed_magnitude, unchecked, std::allocator >; variable_precision_type a_t(a.limbs(), 0, a.size()), b_t(b.limbs(), 0, b.size()); - unsigned as = a.size(); - unsigned bs = b.size(); - unsigned s = as > bs ? as : bs; - unsigned sz = as + bs; - unsigned storage_size = karatsuba_storage_size(s); + std::size_t as = a.size(); + std::size_t bs = b.size(); + std::size_t s = as > bs ? as : bs; + std::size_t sz = as + bs; + std::size_t storage_size = karatsuba_storage_size(s); result.resize(sz, sz); variable_precision_type t(result.limbs(), 0, result.size()); @@ -336,7 +336,7 @@ setup_karatsuba( multiply_karatsuba(t, a_t, b_t, storage); } -template +template inline BOOST_MP_CXX14_CONSTEXPR void eval_multiply_comba( cpp_int_backend& result, @@ -348,7 +348,7 @@ eval_multiply_comba( // Comba Multiplier - based on Paul Comba's // Exponentiation cryptosystems on the IBM PC, 1990 // - int as = a.size(), + std::ptrdiff_t as = a.size(), bs = b.size(), rs = result.size(); typename cpp_int_backend::limb_pointer pr = result.limbs(); @@ -356,11 +356,11 @@ eval_multiply_comba( double_limb_type carry = 0, temp = 0; limb_type overflow = 0; - const unsigned limb_bits = sizeof(limb_type) * CHAR_BIT; + const std::size_t limb_bits = sizeof(limb_type) * CHAR_BIT; const bool must_throw = rs < as + bs - 1; - for (int r = 0, lim = (std::min)(rs, as + bs - 1); r < lim; ++r, overflow = 0) + for (std::ptrdiff_t r = 0, lim = (std::min)(rs, as + bs - 1); r < lim; ++r, overflow = 0) { - int i = r >= as ? as - 1 : r, + std::ptrdiff_t i = r >= as ? as - 1 : r, j = r - i, k = i < bs - j ? i + 1 : bs - j; // min(i+1, bs-j); @@ -386,7 +386,7 @@ eval_multiply_comba( *pr = static_cast(carry); } } -template +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value && !is_trivial_cpp_int >::value>::type eval_multiply( cpp_int_backend& result, @@ -402,8 +402,8 @@ eval_multiply( // // Trivial cases first: // - unsigned as = a.size(); - unsigned bs = b.size(); + std::size_t as = a.size(); + std::size_t bs = b.size(); typename cpp_int_backend::const_limb_pointer pa = a.limbs(); typename cpp_int_backend::const_limb_pointer pb = b.limbs(); if (as == 1) @@ -466,7 +466,7 @@ eval_multiply( #ifndef BOOST_MP_NO_CONSTEXPR_DETECTION if (BOOST_MP_IS_CONST_EVALUATED(as)) { - for (unsigned i = 0; i < result.size(); ++i) + for (std::size_t i = 0; i < result.size(); ++i) pr[i] = 0; } else @@ -483,11 +483,11 @@ eval_multiply( #else double_limb_type carry = 0; - for (unsigned i = 0; i < as; ++i) + for (std::size_t i = 0; i < as; ++i) { BOOST_MP_ASSERT(result.size() > i); - unsigned inner_limit = !is_fixed_precision >::value ? bs : (std::min)(result.size() - i, bs); - unsigned j = 0; + std::size_t inner_limit = !is_fixed_precision >::value ? bs : (std::min)(result.size() - i, bs); + std::size_t j = 0; for (; j < inner_limit; ++j) { BOOST_MP_ASSERT(i + j < result.size()); @@ -527,7 +527,7 @@ eval_multiply( result.sign(a.sign() != b.sign()); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_multiply( cpp_int_backend& result, @@ -537,7 +537,7 @@ eval_multiply( eval_multiply(result, result, a); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_multiply(cpp_int_backend& result, const limb_type& val) noexcept((noexcept(eval_multiply(std::declval&>(), std::declval&>(), std::declval())))) @@ -545,7 +545,7 @@ eval_multiply(cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_multiply( cpp_int_backend& result, @@ -572,7 +572,7 @@ eval_multiply( } } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_multiply(cpp_int_backend& result, const double_limb_type& val) noexcept((noexcept(eval_multiply(std::declval&>(), std::declval&>(), std::declval())))) @@ -580,7 +580,7 @@ eval_multiply(cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_multiply( cpp_int_backend& result, @@ -597,7 +597,7 @@ eval_multiply( } } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_multiply(cpp_int_backend& result, const signed_limb_type& val) noexcept((noexcept(eval_multiply(std::declval&>(), std::declval&>(), std::declval())))) @@ -605,7 +605,7 @@ eval_multiply(cpp_int_backend +template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value && !is_trivial_cpp_int >::value>::type eval_multiply( cpp_int_backend& result, @@ -639,7 +639,7 @@ eval_multiply( eval_multiply(result, a, t); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if >::value>::type eval_multiply(cpp_int_backend& result, const signed_double_limb_type& val) noexcept( @@ -653,7 +653,7 @@ eval_multiply(cpp_int_backend +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && (is_signed_number >::value || is_signed_number >::value)>::type eval_multiply( @@ -665,7 +665,7 @@ eval_multiply( result.normalize(); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_unsigned_number >::value>::type eval_multiply( @@ -676,7 +676,7 @@ eval_multiply( result.normalize(); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && (is_signed_number >::value || is_signed_number >::value)>::type eval_multiply( @@ -689,7 +689,7 @@ eval_multiply( result.normalize(); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< is_trivial_cpp_int >::value && is_unsigned_number >::value>::type eval_multiply( @@ -704,7 +704,7 @@ eval_multiply( // // Special routines for multiplying two integers to obtain a multiprecision result: // -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value>::type eval_multiply( @@ -712,7 +712,7 @@ eval_multiply( signed_double_limb_type a, signed_double_limb_type b) { constexpr const signed_double_limb_type mask = ~static_cast(0); - constexpr const unsigned limb_bits = sizeof(limb_type) * CHAR_BIT; + constexpr const std::size_t limb_bits = sizeof(limb_type) * CHAR_BIT; bool s = false; if (a < 0) @@ -757,7 +757,7 @@ eval_multiply( result.normalize(); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value>::type eval_multiply( @@ -765,7 +765,7 @@ eval_multiply( double_limb_type a, double_limb_type b) { constexpr const signed_double_limb_type mask = ~static_cast(0); - constexpr const unsigned limb_bits = sizeof(limb_type) * CHAR_BIT; + constexpr const std::size_t limb_bits = sizeof(limb_type) * CHAR_BIT; double_limb_type w = a & mask; double_limb_type x = a >> limb_bits; @@ -807,8 +807,8 @@ eval_multiply( result.normalize(); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if< !is_trivial_cpp_int >::value && is_trivial_cpp_int >::value && is_trivial_cpp_int >::value>::type eval_multiply( @@ -821,7 +821,7 @@ eval_multiply( result.sign(a.sign() != b.sign()); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value && boost::multiprecision::detail::is_integral::value && (sizeof(SI) <= sizeof(signed_double_limb_type) / 2)>::type eval_multiply( cpp_int_backend& result, @@ -830,7 +830,7 @@ eval_multiply( result = static_cast(a) * static_cast(b); } -template +template BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value && (sizeof(UI) <= sizeof(signed_double_limb_type) / 2)>::type eval_multiply( cpp_int_backend& result, diff --git a/include/boost/multiprecision/cpp_int/serialize.hpp b/include/boost/multiprecision/cpp_int/serialize.hpp index c83d856d..e4196194 100644 --- a/include/boost/multiprecision/cpp_int/serialize.hpp +++ b/include/boost/multiprecision/cpp_int/serialize.hpp @@ -191,7 +191,7 @@ void do_serialize(Archive& ar, Int& val, std::integral_constant cons } // namespace cpp_int_detail -template +template void serialize(Archive& ar, mp::cpp_int_backend& val, const unsigned int /*version*/) { using archive_save_tag = typename Archive::is_saving ; diff --git a/include/boost/multiprecision/debug_adaptor.hpp b/include/boost/multiprecision/debug_adaptor.hpp index 38cc4ed2..e892c441 100644 --- a/include/boost/multiprecision/debug_adaptor.hpp +++ b/include/boost/multiprecision/debug_adaptor.hpp @@ -462,49 +462,49 @@ inline void eval_right_shift(debug_adaptor& arg, const debug_adaptor -inline unsigned eval_integer_modulus(const debug_adaptor& arg, const T& a) +inline T eval_integer_modulus(const debug_adaptor& arg, const T& a) { using default_ops::eval_integer_modulus; return eval_integer_modulus(arg.value(), a); } template -inline unsigned eval_lsb(const debug_adaptor& arg) +inline std::size_t eval_lsb(const debug_adaptor& arg) { using default_ops::eval_lsb; return eval_lsb(arg.value()); } template -inline unsigned eval_msb(const debug_adaptor& arg) +inline std::size_t eval_msb(const debug_adaptor& arg) { using default_ops::eval_msb; return eval_msb(arg.value()); } template -inline bool eval_bit_test(const debug_adaptor& arg, unsigned a) +inline bool eval_bit_test(const debug_adaptor& arg, std::size_t a) { using default_ops::eval_bit_test; return eval_bit_test(arg.value(), a); } template -inline void eval_bit_set(const debug_adaptor& arg, unsigned a) +inline void eval_bit_set(const debug_adaptor& arg, std::size_t a) { using default_ops::eval_bit_set; eval_bit_set(arg.value(), a); arg.update_view(); } template -inline void eval_bit_unset(const debug_adaptor& arg, unsigned a) +inline void eval_bit_unset(const debug_adaptor& arg, std::size_t a) { using default_ops::eval_bit_unset; eval_bit_unset(arg.value(), a); arg.update_view(); } template -inline void eval_bit_flip(const debug_adaptor& arg, unsigned a) +inline void eval_bit_flip(const debug_adaptor& arg, std::size_t a) { using default_ops::eval_bit_flip; eval_bit_flip(arg.value(), a); diff --git a/include/boost/multiprecision/detail/bitscan.hpp b/include/boost/multiprecision/detail/bitscan.hpp index 21d51ac9..11cb0051 100644 --- a/include/boost/multiprecision/detail/bitscan.hpp +++ b/include/boost/multiprecision/detail/bitscan.hpp @@ -20,9 +20,9 @@ namespace boost { namespace multiprecision { namespace detail { template -inline BOOST_MP_CXX14_CONSTEXPR unsigned find_lsb_default(Unsigned mask) +inline BOOST_MP_CXX14_CONSTEXPR std::size_t find_lsb_default(Unsigned mask) { - unsigned result = 0; + std::size_t result = 0; while (!(mask & 1u)) { mask >>= 1; @@ -32,9 +32,9 @@ inline BOOST_MP_CXX14_CONSTEXPR unsigned find_lsb_default(Unsigned mask) } template -inline BOOST_MP_CXX14_CONSTEXPR unsigned find_msb_default(Unsigned mask) +inline BOOST_MP_CXX14_CONSTEXPR std::size_t find_msb_default(Unsigned mask) { - unsigned index = 0; + std::size_t index = 0; while (mask) { ++index; @@ -44,13 +44,13 @@ inline BOOST_MP_CXX14_CONSTEXPR unsigned find_msb_default(Unsigned mask) } template -inline BOOST_MP_CXX14_CONSTEXPR unsigned find_lsb(Unsigned mask, const std::integral_constant&) +inline BOOST_MP_CXX14_CONSTEXPR std::size_t find_lsb(Unsigned mask, const std::integral_constant&) { return find_lsb_default(mask); } template -inline BOOST_MP_CXX14_CONSTEXPR unsigned find_msb(Unsigned mask, const std::integral_constant&) +inline BOOST_MP_CXX14_CONSTEXPR std::size_t find_msb(Unsigned mask, const std::integral_constant&) { return find_msb_default(mask); } @@ -59,14 +59,14 @@ inline BOOST_MP_CXX14_CONSTEXPR unsigned find_msb(Unsigned mask, const std::inte #pragma intrinsic(_BitScanForward, _BitScanReverse) -BOOST_FORCEINLINE unsigned find_lsb(unsigned long mask, const std::integral_constant&) +BOOST_FORCEINLINE std::size_t find_lsb(unsigned long mask, const std::integral_constant&) { unsigned long result; _BitScanForward(&result, mask); return result; } -BOOST_FORCEINLINE unsigned find_msb(unsigned long mask, const std::integral_constant&) +BOOST_FORCEINLINE std::size_t find_msb(unsigned long mask, const std::integral_constant&) { unsigned long result; _BitScanReverse(&result, mask); @@ -76,14 +76,14 @@ BOOST_FORCEINLINE unsigned find_msb(unsigned long mask, const std::integral_cons #pragma intrinsic(_BitScanForward64, _BitScanReverse64) -BOOST_FORCEINLINE unsigned find_lsb(unsigned __int64 mask, const std::integral_constant&) +BOOST_FORCEINLINE std::size_t find_lsb(unsigned __int64 mask, const std::integral_constant&) { unsigned long result; _BitScanForward64(&result, mask); return result; } template -BOOST_FORCEINLINE unsigned find_msb(Unsigned mask, const std::integral_constant&) +BOOST_FORCEINLINE std::size_t find_msb(Unsigned mask, const std::integral_constant&) { unsigned long result; _BitScanReverse64(&result, mask); @@ -92,7 +92,7 @@ BOOST_FORCEINLINE unsigned find_msb(Unsigned mask, const std::integral_constant< #endif template -BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR unsigned find_lsb(Unsigned mask) +BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_lsb(Unsigned mask) { using ui_type = typename boost::multiprecision::detail::make_unsigned::type; using tag_type = typename std::conditional< @@ -118,7 +118,7 @@ BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR unsigned find_lsb(Unsigned mask) } template -BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR unsigned find_msb(Unsigned mask) +BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_msb(Unsigned mask) { using ui_type = typename boost::multiprecision::detail::make_unsigned::type; using tag_type = typename std::conditional< @@ -145,27 +145,27 @@ BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR unsigned find_msb(Unsigned mask) #elif defined(BOOST_GCC) || defined(__clang__) || (defined(BOOST_INTEL) && defined(__GNUC__)) -BOOST_FORCEINLINE unsigned find_lsb(unsigned mask, std::integral_constant const&) +BOOST_FORCEINLINE std::size_t find_lsb(std::size_t mask, std::integral_constant const&) { return __builtin_ctz(mask); } -BOOST_FORCEINLINE unsigned find_lsb(unsigned long mask, std::integral_constant const&) +BOOST_FORCEINLINE std::size_t find_lsb(unsigned long mask, std::integral_constant const&) { return __builtin_ctzl(mask); } -BOOST_FORCEINLINE unsigned find_lsb(unsigned long long mask, std::integral_constant const&) +BOOST_FORCEINLINE std::size_t find_lsb(unsigned long long mask, std::integral_constant const&) { return __builtin_ctzll(mask); } -BOOST_FORCEINLINE unsigned find_msb(unsigned mask, std::integral_constant const&) +BOOST_FORCEINLINE std::size_t find_msb(std::size_t mask, std::integral_constant const&) { return sizeof(unsigned) * CHAR_BIT - 1 - __builtin_clz(mask); } -BOOST_FORCEINLINE unsigned find_msb(unsigned long mask, std::integral_constant const&) +BOOST_FORCEINLINE std::size_t find_msb(unsigned long mask, std::integral_constant const&) { return sizeof(unsigned long) * CHAR_BIT - 1 - __builtin_clzl(mask); } -BOOST_FORCEINLINE unsigned find_msb(unsigned long long mask, std::integral_constant const&) +BOOST_FORCEINLINE std::size_t find_msb(unsigned long long mask, std::integral_constant const&) { return sizeof(unsigned long long) * CHAR_BIT - 1 - __builtin_clzll(mask); } @@ -173,7 +173,7 @@ BOOST_FORCEINLINE unsigned find_msb(unsigned long long mask, std::integral_const __extension__ using uint128_type = unsigned __int128; -BOOST_FORCEINLINE unsigned find_msb(uint128_type mask, std::integral_constant const&) +BOOST_FORCEINLINE std::size_t find_msb(uint128_type mask, std::integral_constant const&) { union { @@ -191,7 +191,7 @@ BOOST_FORCEINLINE unsigned find_msb(uint128_type mask, std::integral_constant()); #endif } -BOOST_FORCEINLINE unsigned find_lsb(uint128_type mask, std::integral_constant const&) +BOOST_FORCEINLINE std::size_t find_lsb(uint128_type mask, std::integral_constant const&) { union { @@ -212,7 +212,7 @@ BOOST_FORCEINLINE unsigned find_lsb(uint128_type mask, std::integral_constant -BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR unsigned find_lsb(Unsigned mask) +BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_lsb(Unsigned mask) { using ui_type = typename boost::multiprecision::detail::make_unsigned::type; using tag_type = typename std::conditional< @@ -235,7 +235,7 @@ BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR unsigned find_lsb(Unsigned mask) return find_lsb(static_cast(mask), tag_type()); } template -BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR unsigned find_msb(Unsigned mask) +BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_msb(Unsigned mask) { using ui_type = typename boost::multiprecision::detail::make_unsigned::type; using tag_type = typename std::conditional< @@ -258,16 +258,16 @@ BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR unsigned find_msb(Unsigned mask) return find_msb(static_cast(mask), tag_type()); } #elif defined(BOOST_INTEL) -BOOST_FORCEINLINE unsigned find_lsb(unsigned mask, std::integral_constant const&) +BOOST_FORCEINLINE std::size_t find_lsb(std::size_t mask, std::integral_constant const&) { return _bit_scan_forward(mask); } -BOOST_FORCEINLINE unsigned find_msb(unsigned mask, std::integral_constant const&) +BOOST_FORCEINLINE std::size_t find_msb(std::size_t mask, std::integral_constant const&) { return _bit_scan_reverse(mask); } template -BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR unsigned find_lsb(Unsigned mask) +BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_lsb(Unsigned mask) { using ui_type = typename boost::multiprecision::detail::make_unsigned::type; using tag_type = typename std::conditional< @@ -284,7 +284,7 @@ BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR unsigned find_lsb(Unsigned mask) return find_lsb(static_cast(mask), tag_type()); } template -BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR unsigned find_msb(Unsigned mask) +BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_msb(Unsigned mask) { using ui_type = typename boost::multiprecision::detail::make_unsigned::type; using tag_type = typename std::conditional< @@ -302,12 +302,12 @@ BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR unsigned find_msb(Unsigned mask) } #else template -BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR unsigned find_lsb(Unsigned mask) +BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_lsb(Unsigned mask) { return find_lsb(mask, std::integral_constant()); } template -BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR unsigned find_msb(Unsigned mask) +BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_msb(Unsigned mask) { return find_msb(mask, std::integral_constant()); } diff --git a/include/boost/multiprecision/detail/default_ops.hpp b/include/boost/multiprecision/detail/default_ops.hpp index a4a46a6b..89a02a63 100644 --- a/include/boost/multiprecision/detail/default_ops.hpp +++ b/include/boost/multiprecision/detail/default_ops.hpp @@ -1566,7 +1566,7 @@ inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if -inline BOOST_MP_CXX14_CONSTEXPR unsigned eval_lsb(const T& val) +inline BOOST_MP_CXX14_CONSTEXPR std::size_t eval_lsb(const T& val) { using ui_type = typename boost::multiprecision::detail::canonical::type; int c = eval_get_sign(val); @@ -1578,7 +1578,7 @@ inline BOOST_MP_CXX14_CONSTEXPR unsigned eval_lsb(const T& val) { BOOST_MP_THROW_EXCEPTION(std::domain_error("Testing individual bits in negative values is not supported - results are undefined.")); } - unsigned result = 0; + std::size_t result = 0; T mask, t; mask = ui_type(1); do @@ -1592,7 +1592,7 @@ inline BOOST_MP_CXX14_CONSTEXPR unsigned eval_lsb(const T& val) } template -inline BOOST_MP_CXX14_CONSTEXPR int eval_msb(const T& val) +inline BOOST_MP_CXX14_CONSTEXPR std::ptrdiff_t eval_msb(const T& val) { int c = eval_get_sign(val); if (c == 0) @@ -1611,7 +1611,7 @@ inline BOOST_MP_CXX14_CONSTEXPR int eval_msb(const T& val) // backends it's likely that there will always be a more efficient // native implementation possible. // - unsigned result = 0; + std::size_t result = 0; T t(val); while (!eval_is_zero(t)) { @@ -1622,7 +1622,7 @@ inline BOOST_MP_CXX14_CONSTEXPR int eval_msb(const T& val) } template -inline BOOST_MP_CXX14_CONSTEXPR bool eval_bit_test(const T& val, unsigned index) +inline BOOST_MP_CXX14_CONSTEXPR bool eval_bit_test(const T& val, std::size_t index) { using ui_type = typename boost::multiprecision::detail::canonical::type; T mask, t; @@ -1633,7 +1633,7 @@ inline BOOST_MP_CXX14_CONSTEXPR bool eval_bit_test(const T& val, unsigned index) } template -inline BOOST_MP_CXX14_CONSTEXPR void eval_bit_set(T& val, unsigned index) +inline BOOST_MP_CXX14_CONSTEXPR void eval_bit_set(T& val, std::size_t index) { using ui_type = typename boost::multiprecision::detail::canonical::type; T mask; @@ -1643,7 +1643,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void eval_bit_set(T& val, unsigned index) } template -inline BOOST_MP_CXX14_CONSTEXPR void eval_bit_flip(T& val, unsigned index) +inline BOOST_MP_CXX14_CONSTEXPR void eval_bit_flip(T& val, std::size_t index) { using ui_type = typename boost::multiprecision::detail::canonical::type; T mask; @@ -1653,7 +1653,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void eval_bit_flip(T& val, unsigned index) } template -inline BOOST_MP_CXX14_CONSTEXPR void eval_bit_unset(T& val, unsigned index) +inline BOOST_MP_CXX14_CONSTEXPR void eval_bit_unset(T& val, std::size_t index) { using ui_type = typename boost::multiprecision::detail::canonical::type; T mask, t; @@ -1761,7 +1761,7 @@ void BOOST_MP_CXX14_CONSTEXPR eval_integer_sqrt_bitwise(B& s, B& r, const B& x) r = ui_type(0u); return; } - int g = eval_msb(x); + std::ptrdiff_t g = eval_msb(x); if (g <= 1) { s = ui_type(1); @@ -1772,14 +1772,14 @@ void BOOST_MP_CXX14_CONSTEXPR eval_integer_sqrt_bitwise(B& s, B& r, const B& x) B t; r = x; g /= 2; - int org_g = g; + std::ptrdiff_t org_g = g; eval_bit_set(s, g); eval_bit_set(t, 2 * g); eval_subtract(r, x, t); --g; if (eval_get_sign(r) == 0) return; - int msbr = eval_msb(r); + std::ptrdiff_t msbr = eval_msb(r); do { if (msbr >= org_g + g + 1) diff --git a/include/boost/multiprecision/detail/float_string_cvt.hpp b/include/boost/multiprecision/detail/float_string_cvt.hpp index 42ddb679..7138d5be 100644 --- a/include/boost/multiprecision/detail/float_string_cvt.hpp +++ b/include/boost/multiprecision/detail/float_string_cvt.hpp @@ -20,7 +20,7 @@ namespace boost { namespace multiprecision { namespace detail { template -inline void round_string_up_at(std::string& s, int pos, I& expon) +inline void round_string_up_at(std::string& s, std::ptrdiff_t pos, I& expon) { // // Rounds up a string representation of a number at pos: diff --git a/include/boost/multiprecision/detail/generic_interconvert.hpp b/include/boost/multiprecision/detail/generic_interconvert.hpp index daeb9c0d..e0b69c00 100644 --- a/include/boost/multiprecision/detail/generic_interconvert.hpp +++ b/include/boost/multiprecision/detail/generic_interconvert.hpp @@ -258,7 +258,7 @@ R safe_convert_to_float(const LargeInteger& i) { LargeInteger val(i); make_positive(val); - unsigned mb = msb(val); + std::size_t mb = msb(val); if (mb >= std::numeric_limits::max_exponent) { int scale_factor = (int)mb + 1 - std::numeric_limits::max_exponent; @@ -330,15 +330,15 @@ generic_convert_rational_to_float_imp(To& result, Integer& num, Integer& denom, s = true; num = -num; } - int denom_bits = msb(denom); - int shift = std::numeric_limits::digits + denom_bits - msb(num); + std::ptrdiff_t denom_bits = msb(denom); + std::ptrdiff_t shift = std::numeric_limits::digits + denom_bits - msb(num); if (shift > 0) num <<= shift; else if (shift < 0) denom <<= boost::multiprecision::detail::unsigned_abs(shift); Integer q, r; divide_qr(num, denom, q, r); - int q_bits = msb(q); + std::ptrdiff_t q_bits = msb(q); if (q_bits == std::numeric_limits::digits - 1) { // @@ -367,7 +367,7 @@ generic_convert_rational_to_float_imp(To& result, Integer& num, Integer& denom, } using std::ldexp; result = do_cast(q); - result = ldexp(result, -shift); + result = ldexp(result, (int)-shift); if (s) result = -result; } diff --git a/include/boost/multiprecision/detail/integer_ops.hpp b/include/boost/multiprecision/detail/integer_ops.hpp index c426c317..a780f334 100644 --- a/include/boost/multiprecision/detail/integer_ops.hpp +++ b/include/boost/multiprecision/detail/integer_ops.hpp @@ -41,7 +41,7 @@ inline BOOST_MP_CXX14_CONSTEXPR void eval_gcd(B& result, const B& a, const B& b) using default_ops::eval_is_zero; using default_ops::eval_lsb; - int shift(0); + std::ptrdiff_t shift(0); B u(a), v(b); @@ -71,8 +71,8 @@ inline BOOST_MP_CXX14_CONSTEXPR void eval_gcd(B& result, const B& a, const B& b) /* Let shift := lg K, where K is the greatest power of 2 dividing both u and v. */ - unsigned us = eval_lsb(u); - unsigned vs = eval_lsb(v); + std::size_t us = eval_lsb(u); + std::size_t vs = eval_lsb(v); shift = (std::min)(us, vs); eval_right_shift(u, us); eval_right_shift(v, vs); @@ -167,7 +167,7 @@ integer_modulus(const multiprecision::detail::expression& x } template -inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value == number_kind_integer, unsigned>::type +inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value == number_kind_integer, std::size_t>::type lsb(const number& x) { using default_ops::eval_lsb; @@ -175,7 +175,7 @@ lsb(const number& x) } template -inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::result_type>::value == number_kind_integer, unsigned>::type +inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::result_type>::value == number_kind_integer, std::size_t>::type lsb(const multiprecision::detail::expression& x) { using number_type = typename multiprecision::detail::expression::result_type; @@ -185,7 +185,7 @@ lsb(const multiprecision::detail::expression& x) } template -inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value == number_kind_integer, unsigned>::type +inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value == number_kind_integer, std::size_t>::type msb(const number& x) { using default_ops::eval_msb; @@ -193,7 +193,7 @@ msb(const number& x) } template -inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::result_type>::value == number_kind_integer, unsigned>::type +inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::result_type>::value == number_kind_integer, std::size_t>::type msb(const multiprecision::detail::expression& x) { using number_type = typename multiprecision::detail::expression::result_type; @@ -204,7 +204,7 @@ msb(const multiprecision::detail::expression& x) template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value == number_kind_integer, bool>::type -bit_test(const number& x, unsigned index) +bit_test(const number& x, std::size_t index) { using default_ops::eval_bit_test; return eval_bit_test(x.backend(), index); @@ -212,7 +212,7 @@ bit_test(const number& x, unsigned index) template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::result_type>::value == number_kind_integer, bool>::type -bit_test(const multiprecision::detail::expression& x, unsigned index) +bit_test(const multiprecision::detail::expression& x, std::size_t index) { using number_type = typename multiprecision::detail::expression::result_type; number_type n(x); @@ -222,7 +222,7 @@ bit_test(const multiprecision::detail::expression& x, unsig template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value == number_kind_integer, number&>::type -bit_set(number& x, unsigned index) +bit_set(number& x, std::size_t index) { using default_ops::eval_bit_set; eval_bit_set(x.backend(), index); @@ -231,7 +231,7 @@ bit_set(number& x, unsigned index) template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value == number_kind_integer, number&>::type -bit_unset(number& x, unsigned index) +bit_unset(number& x, std::size_t index) { using default_ops::eval_bit_unset; eval_bit_unset(x.backend(), index); @@ -240,7 +240,7 @@ bit_unset(number& x, unsigned index) template inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value == number_kind_integer, number&>::type -bit_flip(number& x, unsigned index) +bit_flip(number& x, std::size_t index) { using default_ops::eval_bit_flip; eval_bit_flip(x.backend(), index); diff --git a/include/boost/multiprecision/detail/precision.hpp b/include/boost/multiprecision/detail/precision.hpp index f33c6333..19de0917 100644 --- a/include/boost/multiprecision/detail/precision.hpp +++ b/include/boost/multiprecision/detail/precision.hpp @@ -27,7 +27,7 @@ inline BOOST_MP_CXX14_CONSTEXPR unsigned current_precision_of_last_chance_imp(co // least-significant-bit, ie the number of bits required to represent the // the value assuming we will have an exponent to shift things by: // - return val.is_zero() ? 1 : 1 + digits2_2_10(msb(abs(val)) - lsb(abs(val)) + 1); + return static_cast(val.is_zero() ? 1 : 1 + digits2_2_10(msb(abs(val)) - lsb(abs(val)) + 1)); } template inline BOOST_MP_CXX14_CONSTEXPR unsigned current_precision_of_last_chance_imp(const boost::multiprecision::number& val, const std::integral_constant&) diff --git a/include/boost/multiprecision/gmp.hpp b/include/boost/multiprecision/gmp.hpp index 06a57788..151daa93 100644 --- a/include/boost/multiprecision/gmp.hpp +++ b/include/boost/multiprecision/gmp.hpp @@ -2020,7 +2020,7 @@ inline void eval_integer_sqrt(gmp_int& s, gmp_int& r, const gmp_int& x) mpz_sqrtrem(s.data(), r.data(), x.data()); } -inline unsigned eval_lsb(const gmp_int& val) +inline std::size_t eval_lsb(const gmp_int& val) { int c = eval_get_sign(val); if (c == 0) @@ -2034,7 +2034,7 @@ inline unsigned eval_lsb(const gmp_int& val) return static_cast(mpz_scan1(val.data(), 0)); } -inline unsigned eval_msb(const gmp_int& val) +inline std::size_t eval_msb(const gmp_int& val) { int c = eval_get_sign(val); if (c == 0) @@ -2048,22 +2048,22 @@ inline unsigned eval_msb(const gmp_int& val) return static_cast(mpz_sizeinbase(val.data(), 2) - 1); } -inline bool eval_bit_test(const gmp_int& val, unsigned index) +inline bool eval_bit_test(const gmp_int& val, std::size_t index) { return mpz_tstbit(val.data(), index) ? true : false; } -inline void eval_bit_set(gmp_int& val, unsigned index) +inline void eval_bit_set(gmp_int& val, std::size_t index) { mpz_setbit(val.data(), index); } -inline void eval_bit_unset(gmp_int& val, unsigned index) +inline void eval_bit_unset(gmp_int& val, std::size_t index) { mpz_clrbit(val.data(), index); } -inline void eval_bit_flip(gmp_int& val, unsigned index) +inline void eval_bit_flip(gmp_int& val, std::size_t index) { mpz_combit(val.data(), index); } diff --git a/include/boost/multiprecision/integer.hpp b/include/boost/multiprecision/integer.hpp index b3dbfd95..b1e2abcb 100644 --- a/include/boost/multiprecision/integer.hpp +++ b/include/boost/multiprecision/integer.hpp @@ -112,7 +112,7 @@ powm(const I1& a, I2 b, I3 c) } template -BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value, unsigned>::type lsb(const Integer& val) +BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value, std::size_t>::type lsb(const Integer& val) { if (val <= 0) { @@ -129,7 +129,7 @@ BOOST_MP_CXX14_CONSTEXPR typename std::enable_if -BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value, unsigned>::type msb(Integer val) +BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value, std::size_t>::type msb(Integer val) { if (val <= 0) { @@ -146,7 +146,7 @@ BOOST_MP_CXX14_CONSTEXPR typename std::enable_if -BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value, bool>::type bit_test(const Integer& val, unsigned index) +BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value, bool>::type bit_test(const Integer& val, std::size_t index) { Integer mask = 1; if (index >= sizeof(Integer) * CHAR_BIT) @@ -157,7 +157,7 @@ BOOST_MP_CXX14_CONSTEXPR typename std::enable_if -BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value, Integer&>::type bit_set(Integer& val, unsigned index) +BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value, Integer&>::type bit_set(Integer& val, std::size_t index) { Integer mask = 1; if (index >= sizeof(Integer) * CHAR_BIT) @@ -169,7 +169,7 @@ BOOST_MP_CXX14_CONSTEXPR typename std::enable_if -BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value, Integer&>::type bit_unset(Integer& val, unsigned index) +BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value, Integer&>::type bit_unset(Integer& val, std::size_t index) { Integer mask = 1; if (index >= sizeof(Integer) * CHAR_BIT) @@ -181,7 +181,7 @@ BOOST_MP_CXX14_CONSTEXPR typename std::enable_if -BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value, Integer&>::type bit_flip(Integer& val, unsigned index) +BOOST_MP_CXX14_CONSTEXPR typename std::enable_if::value, Integer&>::type bit_flip(Integer& val, std::size_t index) { Integer mask = 1; if (index >= sizeof(Integer) * CHAR_BIT) @@ -288,7 +288,7 @@ BOOST_MP_CXX14_CONSTEXPR Integer bitwise_sqrt(const Integer& x, Integer& r) r = 0; return s; } - int g = msb(x); + std::ptrdiff_t g = msb(x); if (g == 0) { r = 1; diff --git a/include/boost/multiprecision/logged_adaptor.hpp b/include/boost/multiprecision/logged_adaptor.hpp index 8525dca0..b24e1766 100644 --- a/include/boost/multiprecision/logged_adaptor.hpp +++ b/include/boost/multiprecision/logged_adaptor.hpp @@ -530,37 +530,37 @@ inline void eval_right_shift(logged_adaptor& arg, const logged_adaptor< } template -inline unsigned eval_integer_modulus(const logged_adaptor& arg, const T& a) +inline T eval_integer_modulus(const logged_adaptor& arg, const T& a) { using default_ops::eval_integer_modulus; log_prefix_event(arg.value(), a, "integer-modulus"); - unsigned r = eval_integer_modulus(arg.value(), a); + T r = eval_integer_modulus(arg.value(), a); log_postfix_event(arg.value(), r, "integer-modulus"); return r; } template -inline unsigned eval_lsb(const logged_adaptor& arg) +inline std::size_t eval_lsb(const logged_adaptor& arg) { using default_ops::eval_lsb; log_prefix_event(arg.value(), "least-significant-bit"); - unsigned r = eval_lsb(arg.value()); + std::size_t r = eval_lsb(arg.value()); log_postfix_event(arg.value(), r, "least-significant-bit"); return r; } template -inline unsigned eval_msb(const logged_adaptor& arg) +inline std::size_t eval_msb(const logged_adaptor& arg) { using default_ops::eval_msb; log_prefix_event(arg.value(), "most-significant-bit"); - unsigned r = eval_msb(arg.value()); + std::size_t r = eval_msb(arg.value()); log_postfix_event(arg.value(), r, "most-significant-bit"); return r; } template -inline bool eval_bit_test(const logged_adaptor& arg, unsigned a) +inline bool eval_bit_test(const logged_adaptor& arg, std::size_t a) { using default_ops::eval_bit_test; log_prefix_event(arg.value(), a, "bit-test"); @@ -570,7 +570,7 @@ inline bool eval_bit_test(const logged_adaptor& arg, unsigned a) } template -inline void eval_bit_set(const logged_adaptor& arg, unsigned a) +inline void eval_bit_set(const logged_adaptor& arg, std::size_t a) { using default_ops::eval_bit_set; log_prefix_event(arg.value(), a, "bit-set"); @@ -578,7 +578,7 @@ inline void eval_bit_set(const logged_adaptor& arg, unsigned a) log_postfix_event(arg.value(), arg, "bit-set"); } template -inline void eval_bit_unset(const logged_adaptor& arg, unsigned a) +inline void eval_bit_unset(const logged_adaptor& arg, std::size_t a) { using default_ops::eval_bit_unset; log_prefix_event(arg.value(), a, "bit-unset"); @@ -586,7 +586,7 @@ inline void eval_bit_unset(const logged_adaptor& arg, unsigned a) log_postfix_event(arg.value(), arg, "bit-unset"); } template -inline void eval_bit_flip(const logged_adaptor& arg, unsigned a) +inline void eval_bit_flip(const logged_adaptor& arg, std::size_t a) { using default_ops::eval_bit_flip; log_prefix_event(arg.value(), a, "bit-flip"); diff --git a/include/boost/multiprecision/miller_rabin.hpp b/include/boost/multiprecision/miller_rabin.hpp index c95cbd3f..b1ba622f 100644 --- a/include/boost/multiprecision/miller_rabin.hpp +++ b/include/boost/multiprecision/miller_rabin.hpp @@ -27,7 +27,7 @@ bool check_small_factors(const I& n) std::uint32_t m1 = integer_modulus(n, pp1); - for (unsigned i = 0; i < sizeof(small_factors1) / sizeof(small_factors1[0]); ++i) + for (std::size_t i = 0; i < sizeof(small_factors1) / sizeof(small_factors1[0]); ++i) { BOOST_MP_ASSERT(pp1 % small_factors1[i] == 0); if (m1 % small_factors1[i] == 0) @@ -40,7 +40,7 @@ bool check_small_factors(const I& n) m1 = integer_modulus(n, pp2); - for (unsigned i = 0; i < sizeof(small_factors2) / sizeof(small_factors2[0]); ++i) + for (std::size_t i = 0; i < sizeof(small_factors2) / sizeof(small_factors2[0]); ++i) { BOOST_MP_ASSERT(pp2 % small_factors2[i] == 0); if (m1 % small_factors2[i] == 0) @@ -53,7 +53,7 @@ bool check_small_factors(const I& n) m1 = integer_modulus(n, pp3); - for (unsigned i = 0; i < sizeof(small_factors3) / sizeof(small_factors3[0]); ++i) + for (std::size_t i = 0; i < sizeof(small_factors3) / sizeof(small_factors3[0]); ++i) { BOOST_MP_ASSERT(pp3 % small_factors3[i] == 0); if (m1 % small_factors3[i] == 0) @@ -66,7 +66,7 @@ bool check_small_factors(const I& n) m1 = integer_modulus(n, pp4); - for (unsigned i = 0; i < sizeof(small_factors4) / sizeof(small_factors4[0]); ++i) + for (std::size_t i = 0; i < sizeof(small_factors4) / sizeof(small_factors4[0]); ++i) { BOOST_MP_ASSERT(pp4 % small_factors4[i] == 0); if (m1 % small_factors4[i] == 0) @@ -89,11 +89,11 @@ bool check_small_factors(const I& n) 181u * 191u * 193u * 197u, 199u * 211u * 223u * 227u}; - for (unsigned k = 0; k < sizeof(pp5) / sizeof(*pp5); ++k) + for (std::size_t k = 0; k < sizeof(pp5) / sizeof(*pp5); ++k) { m1 = integer_modulus(n, pp5[k]); - for (unsigned i = 0; i < 4; ++i) + for (std::size_t i = 0; i < 4; ++i) { BOOST_MP_ASSERT(pp5[k] % small_factors5[k][i] == 0); if (m1 % small_factors5[k][i] == 0) @@ -103,7 +103,7 @@ bool check_small_factors(const I& n) return true; } -inline bool is_small_prime(unsigned n) +inline bool is_small_prime(std::size_t n) { constexpr const unsigned char p[] = { @@ -113,7 +113,7 @@ inline bool is_small_prime(unsigned n) 127u, 131u, 137u, 139u, 149u, 151u, 157u, 163u, 167u, 173u, 179u, 181u, 191u, 193u, 197u, 199u, 211u, 223u, 227u}; - for (unsigned i = 0; i < sizeof(p) / sizeof(*p); ++i) + for (std::size_t i = 0; i < sizeof(p) / sizeof(*p); ++i) { if (n == p[i]) return true; @@ -138,7 +138,7 @@ cast_to_unsigned(const I& val) template typename std::enable_if::value == number_kind_integer, bool>::type -miller_rabin_test(const I& n, unsigned trials, Engine& gen) +miller_rabin_test(const I& n, std::size_t trials, Engine& gen) { using number_type = I; @@ -162,7 +162,7 @@ miller_rabin_test(const I& n, unsigned trials, Engine& gen) return false; q = n - 1; - unsigned k = lsb(q); + std::size_t k = lsb(q); q >>= k; // Declare our random number generator: @@ -171,11 +171,11 @@ miller_rabin_test(const I& n, unsigned trials, Engine& gen) // // Execute the trials: // - for (unsigned i = 0; i < trials; ++i) + for (std::size_t i = 0; i < trials; ++i) { x = dist(gen); y = powm(x, q, n); - unsigned j = 0; + std::size_t j = 0; while (true) { if (y == nm1) @@ -196,21 +196,21 @@ miller_rabin_test(const I& n, unsigned trials, Engine& gen) template typename std::enable_if::value == number_kind_integer, bool>::type -miller_rabin_test(const I& x, unsigned trials) +miller_rabin_test(const I& x, std::size_t trials) { static std::mt19937 gen; return miller_rabin_test(x, trials, gen); } template -bool miller_rabin_test(const detail::expression& n, unsigned trials, Engine& gen) +bool miller_rabin_test(const detail::expression& n, std::size_t trials, Engine& gen) { using number_type = typename detail::expression::result_type; return miller_rabin_test(number_type(n), trials, gen); } template -bool miller_rabin_test(const detail::expression& n, unsigned trials) +bool miller_rabin_test(const detail::expression& n, std::size_t trials) { using number_type = typename detail::expression::result_type; return miller_rabin_test(number_type(n), trials); diff --git a/include/boost/multiprecision/rational_adaptor.hpp b/include/boost/multiprecision/rational_adaptor.hpp index 9c440aee..b02113e0 100644 --- a/include/boost/multiprecision/rational_adaptor.hpp +++ b/include/boost/multiprecision/rational_adaptor.hpp @@ -234,8 +234,8 @@ struct rational_adaptor } int compare(const rational_adaptor& o) const { - int s1 = eval_get_sign(*this); - int s2 = eval_get_sign(o); + std::ptrdiff_t s1 = eval_get_sign(*this); + std::ptrdiff_t s2 = eval_get_sign(o); if (s1 != s2) { return s1 < s2 ? -1 : 1; diff --git a/include/boost/multiprecision/tommath.hpp b/include/boost/multiprecision/tommath.hpp index c7777322..e9066c8d 100644 --- a/include/boost/multiprecision/tommath.hpp +++ b/include/boost/multiprecision/tommath.hpp @@ -795,7 +795,7 @@ inline void eval_qr(const tommath_int& x, const tommath_int& y, detail::check_tommath_result(mp_div(const_cast< ::mp_int*>(&x.data()), const_cast< ::mp_int*>(&y.data()), &q.data(), &r.data())); } -inline unsigned eval_lsb(const tommath_int& val) +inline std::size_t eval_lsb(const tommath_int& val) { int c = eval_get_sign(val); if (c == 0) @@ -809,7 +809,7 @@ inline unsigned eval_lsb(const tommath_int& val) return mp_cnt_lsb(const_cast< ::mp_int*>(&val.data())); } -inline unsigned eval_msb(const tommath_int& val) +inline std::size_t eval_msb(const tommath_int& val) { int c = eval_get_sign(val); if (c == 0) diff --git a/test/constexpr_test_cpp_int_5.cpp b/test/constexpr_test_cpp_int_5.cpp index f9949bd3..ac9e5b07 100644 --- a/test/constexpr_test_cpp_int_5.cpp +++ b/test/constexpr_test_cpp_int_5.cpp @@ -201,25 +201,25 @@ int main() } // lsb: { - constexpr int i1 = lsb(si1); + constexpr std::size_t i1 = lsb(si1); small_int_backend nc(si1); - int nci = lsb(nc); + std::size_t nci = lsb(nc); BOOST_CHECK_EQUAL(nci, i1); - constexpr std::int32_t k = boost::multiprecision::lsb(i); - std::int32_t ii(i); + constexpr std::size_t k = boost::multiprecision::lsb(i); + std::size_t ii(i); ii = boost::multiprecision::lsb(ii); BOOST_CHECK_EQUAL(ii, k); } // msb: { - constexpr int i1 = msb(si1); + constexpr std::size_t i1 = msb(si1); small_int_backend nc(si1); - int nci = msb(nc); + std::size_t nci = msb(nc); BOOST_CHECK_EQUAL(nci, i1); - constexpr std::int32_t k = boost::multiprecision::msb(i); - std::int32_t ii(i); + constexpr std::size_t k = boost::multiprecision::msb(i); + std::size_t ii(i); ii = boost::multiprecision::msb(ii); BOOST_CHECK_EQUAL(ii, k); } diff --git a/test/standalone_test_arithmetic_cpp_int.cpp b/test/standalone_test_arithmetic_cpp_int.cpp index 992e0fc2..c36dd493 100644 --- a/test/standalone_test_arithmetic_cpp_int.cpp +++ b/test/standalone_test_arithmetic_cpp_int.cpp @@ -10,7 +10,7 @@ #include -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -19,7 +19,7 @@ struct related_type { using type = boost::multiprecision::int256_t; }; -template +template struct related_type, ET> > { using type = boost::multiprecision::number, ET>; diff --git a/test/standalone_test_arithmetic_cpp_rational.cpp b/test/standalone_test_arithmetic_cpp_rational.cpp index 1eb2c9b5..c7e141a5 100644 --- a/test/standalone_test_arithmetic_cpp_rational.cpp +++ b/test/standalone_test_arithmetic_cpp_rational.cpp @@ -10,7 +10,7 @@ #include -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -24,7 +24,7 @@ struct related_type { using type = boost::multiprecision::cpp_int; }; -template +template struct related_type, ET> > { using type = boost::multiprecision::number, ET>; diff --git a/test/standalone_test_arithmetic_int512.cpp b/test/standalone_test_arithmetic_int512.cpp index 80a1cd46..0035a459 100644 --- a/test/standalone_test_arithmetic_int512.cpp +++ b/test/standalone_test_arithmetic_int512.cpp @@ -10,7 +10,7 @@ #include -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -19,7 +19,7 @@ struct related_type { using type = boost::multiprecision::int256_t; }; -template +template struct related_type, ET> > { using type = boost::multiprecision::number, ET>; diff --git a/test/test_arithmetic_cpp_int_1.cpp b/test/test_arithmetic_cpp_int_1.cpp index 268a333a..ae0f60e2 100644 --- a/test/test_arithmetic_cpp_int_1.cpp +++ b/test/test_arithmetic_cpp_int_1.cpp @@ -7,7 +7,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -16,7 +16,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_10.cpp b/test/test_arithmetic_cpp_int_10.cpp index 2e75d14b..6055d853 100644 --- a/test/test_arithmetic_cpp_int_10.cpp +++ b/test/test_arithmetic_cpp_int_10.cpp @@ -7,7 +7,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -16,7 +16,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_11.cpp b/test/test_arithmetic_cpp_int_11.cpp index 84d6d8d0..dfc746ff 100644 --- a/test/test_arithmetic_cpp_int_11.cpp +++ b/test/test_arithmetic_cpp_int_11.cpp @@ -7,11 +7,11 @@ #include "test_arithmetic.hpp" -template +template struct is_checked_cpp_int, ET> > : public std::integral_constant {}; -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -20,7 +20,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_12.cpp b/test/test_arithmetic_cpp_int_12.cpp index 941fe30f..b599af26 100644 --- a/test/test_arithmetic_cpp_int_12.cpp +++ b/test/test_arithmetic_cpp_int_12.cpp @@ -7,11 +7,11 @@ #include "test_arithmetic.hpp" -template +template struct is_checked_cpp_int, ET> > : public std::integral_constant {}; -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -20,7 +20,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_13.cpp b/test/test_arithmetic_cpp_int_13.cpp index 84142edd..90370a65 100644 --- a/test/test_arithmetic_cpp_int_13.cpp +++ b/test/test_arithmetic_cpp_int_13.cpp @@ -7,11 +7,11 @@ #include "test_arithmetic.hpp" -template +template struct is_checked_cpp_int, ET> > : public std::integral_constant {}; -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -20,7 +20,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_14.cpp b/test/test_arithmetic_cpp_int_14.cpp index 0603068b..3115caad 100644 --- a/test/test_arithmetic_cpp_int_14.cpp +++ b/test/test_arithmetic_cpp_int_14.cpp @@ -7,7 +7,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -16,7 +16,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_15.cpp b/test/test_arithmetic_cpp_int_15.cpp index 93d94a2c..d64d3752 100644 --- a/test/test_arithmetic_cpp_int_15.cpp +++ b/test/test_arithmetic_cpp_int_15.cpp @@ -7,11 +7,11 @@ #include "test_arithmetic.hpp" -template +template struct is_checked_cpp_int, ET> > : public std::integral_constant {}; -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -20,7 +20,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_16.cpp b/test/test_arithmetic_cpp_int_16.cpp index 487ad7d6..58d120e8 100644 --- a/test/test_arithmetic_cpp_int_16.cpp +++ b/test/test_arithmetic_cpp_int_16.cpp @@ -7,11 +7,11 @@ #include "test_arithmetic.hpp" -template +template struct is_checked_cpp_int, ET> > : public std::integral_constant {}; -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -20,7 +20,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_17.cpp b/test/test_arithmetic_cpp_int_17.cpp index babe96a8..597e3b27 100644 --- a/test/test_arithmetic_cpp_int_17.cpp +++ b/test/test_arithmetic_cpp_int_17.cpp @@ -7,7 +7,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -16,7 +16,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_18.cpp b/test/test_arithmetic_cpp_int_18.cpp index 9a2bc496..fd8c666f 100644 --- a/test/test_arithmetic_cpp_int_18.cpp +++ b/test/test_arithmetic_cpp_int_18.cpp @@ -7,11 +7,11 @@ #include "test_arithmetic.hpp" -template +template struct is_checked_cpp_int, ET> > : public std::integral_constant {}; -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -20,7 +20,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_19.cpp b/test/test_arithmetic_cpp_int_19.cpp index 7c5f921d..0312e7d4 100644 --- a/test/test_arithmetic_cpp_int_19.cpp +++ b/test/test_arithmetic_cpp_int_19.cpp @@ -7,7 +7,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; diff --git a/test/test_arithmetic_cpp_int_2.cpp b/test/test_arithmetic_cpp_int_2.cpp index 497c204e..067e1d82 100644 --- a/test/test_arithmetic_cpp_int_2.cpp +++ b/test/test_arithmetic_cpp_int_2.cpp @@ -7,7 +7,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -16,7 +16,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_20.cpp b/test/test_arithmetic_cpp_int_20.cpp index e569f1ae..744e8e49 100644 --- a/test/test_arithmetic_cpp_int_20.cpp +++ b/test/test_arithmetic_cpp_int_20.cpp @@ -7,7 +7,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; diff --git a/test/test_arithmetic_cpp_int_21.cpp b/test/test_arithmetic_cpp_int_21.cpp index f5e09674..e5f321b8 100644 --- a/test/test_arithmetic_cpp_int_21.cpp +++ b/test/test_arithmetic_cpp_int_21.cpp @@ -7,7 +7,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; diff --git a/test/test_arithmetic_cpp_int_3.cpp b/test/test_arithmetic_cpp_int_3.cpp index 507e7e8e..f21d69f6 100644 --- a/test/test_arithmetic_cpp_int_3.cpp +++ b/test/test_arithmetic_cpp_int_3.cpp @@ -7,7 +7,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -16,7 +16,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_4.cpp b/test/test_arithmetic_cpp_int_4.cpp index 55679add..70b748f0 100644 --- a/test/test_arithmetic_cpp_int_4.cpp +++ b/test/test_arithmetic_cpp_int_4.cpp @@ -9,7 +9,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -18,7 +18,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_5.cpp b/test/test_arithmetic_cpp_int_5.cpp index 310643f9..40d2bfe3 100644 --- a/test/test_arithmetic_cpp_int_5.cpp +++ b/test/test_arithmetic_cpp_int_5.cpp @@ -7,11 +7,11 @@ #include "test_arithmetic.hpp" -template +template struct is_checked_cpp_int, ET> > : public std::integral_constant {}; -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -20,7 +20,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_6.cpp b/test/test_arithmetic_cpp_int_6.cpp index 90580156..eb2b31c4 100644 --- a/test/test_arithmetic_cpp_int_6.cpp +++ b/test/test_arithmetic_cpp_int_6.cpp @@ -7,7 +7,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -16,7 +16,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_7.cpp b/test/test_arithmetic_cpp_int_7.cpp index 9c8afefb..61c77371 100644 --- a/test/test_arithmetic_cpp_int_7.cpp +++ b/test/test_arithmetic_cpp_int_7.cpp @@ -7,7 +7,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -21,7 +21,7 @@ struct related_type { typedef boost::multiprecision::cpp_int type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_8.cpp b/test/test_arithmetic_cpp_int_8.cpp index 5342f0fc..c8ec5e54 100644 --- a/test/test_arithmetic_cpp_int_8.cpp +++ b/test/test_arithmetic_cpp_int_8.cpp @@ -7,7 +7,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -16,7 +16,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_9.cpp b/test/test_arithmetic_cpp_int_9.cpp index dd2a027a..e2afebce 100644 --- a/test/test_arithmetic_cpp_int_9.cpp +++ b/test/test_arithmetic_cpp_int_9.cpp @@ -7,7 +7,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -16,7 +16,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_br.cpp b/test/test_arithmetic_cpp_int_br.cpp index 2d2c7212..470c87f3 100644 --- a/test/test_arithmetic_cpp_int_br.cpp +++ b/test/test_arithmetic_cpp_int_br.cpp @@ -10,7 +10,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; @@ -19,7 +19,7 @@ struct related_type { typedef boost::multiprecision::int256_t type; }; -template +template struct related_type, ET> > { typedef boost::multiprecision::number, ET> type; diff --git a/test/test_arithmetic_cpp_int_dbg_adptr.cpp b/test/test_arithmetic_cpp_int_dbg_adptr.cpp index 58d2e7aa..335c9cad 100644 --- a/test/test_arithmetic_cpp_int_dbg_adptr.cpp +++ b/test/test_arithmetic_cpp_int_dbg_adptr.cpp @@ -8,7 +8,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; diff --git a/test/test_arithmetic_cpp_int_logged_adptr.cpp b/test/test_arithmetic_cpp_int_logged_adptr.cpp index b00a80dd..cd701e2e 100644 --- a/test/test_arithmetic_cpp_int_logged_adptr.cpp +++ b/test/test_arithmetic_cpp_int_logged_adptr.cpp @@ -8,7 +8,7 @@ #include "test_arithmetic.hpp" -template +template struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant {}; diff --git a/test/test_cpp_int.cpp b/test/test_cpp_int.cpp index dd4535f1..d28b7a1b 100644 --- a/test/test_cpp_int.cpp +++ b/test/test_cpp_int.cpp @@ -75,7 +75,7 @@ T generate_random(unsigned bits_wanted) template struct is_checked_cpp_int : public std::integral_constant {}; -template +template struct is_checked_cpp_int, ET> > : public std::integral_constant {}; diff --git a/test/test_cpp_int_import_export.cpp b/test/test_cpp_int_import_export.cpp index 217cfca3..1791e52a 100644 --- a/test/test_cpp_int_import_export.cpp +++ b/test/test_cpp_int_import_export.cpp @@ -27,7 +27,7 @@ struct unchecked_type typedef T type; }; -template +template struct unchecked_type, ExpressionTemplates> > { typedef boost::multiprecision::number, ExpressionTemplates> type; diff --git a/test/test_cpp_int_karatsuba.cpp b/test/test_cpp_int_karatsuba.cpp index 914c6f3c..fb8df69d 100644 --- a/test/test_cpp_int_karatsuba.cpp +++ b/test/test_cpp_int_karatsuba.cpp @@ -70,7 +70,7 @@ T generate_random(unsigned bits_wanted) template struct is_checked_cpp_int : public std::integral_constant {}; -template +template struct is_checked_cpp_int, ET> > : public std::integral_constant {}; diff --git a/test/test_gcd.cpp b/test/test_gcd.cpp index 9bf02b8d..f38b2703 100644 --- a/test/test_gcd.cpp +++ b/test/test_gcd.cpp @@ -20,7 +20,7 @@ // Just exclude that combination from testing for now as it's purely a testing issue // and we have other compilers that cover this sanity check... // -#if 1// !(defined(__clang__) && (__cplusplus > 201300)) +#if !(defined(__clang__) && (__cplusplus > 201300)) using boost::multiprecision::cpp_int; @@ -79,9 +79,9 @@ namespace boost { namespace multiprecision { namespace backends { -unsigned total_lehmer_gcd_calls = 0; -unsigned total_lehmer_gcd_bits_saved = 0; -unsigned total_lehmer_gcd_cycles = 0; +std::size_t total_lehmer_gcd_calls = 0; +std::size_t total_lehmer_gcd_bits_saved = 0; +std::size_t total_lehmer_gcd_cycles = 0; }}} diff --git a/test/test_int_io.cpp b/test/test_int_io.cpp index 56c36c4d..c0f1cfe0 100644 --- a/test/test_int_io.cpp +++ b/test/test_int_io.cpp @@ -51,7 +51,7 @@ struct unchecked_type }; #ifdef TEST_CPP_INT -template +template struct unchecked_type, ExpressionTemplates> > { typedef boost::multiprecision::number, ExpressionTemplates> type;