diff options
Diffstat (limited to 'boost/multiprecision/cpp_int.hpp')
-rw-r--r-- | boost/multiprecision/cpp_int.hpp | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/boost/multiprecision/cpp_int.hpp b/boost/multiprecision/cpp_int.hpp index b8681677e2..c348020d40 100644 --- a/boost/multiprecision/cpp_int.hpp +++ b/boost/multiprecision/cpp_int.hpp @@ -34,9 +34,10 @@ namespace backends{ #ifdef BOOST_MSVC -// warning C4127: conditional expression is constant #pragma warning(push) -#pragma warning(disable:4127 4351 4293 4996 4307 4702 6285) +#pragma warning(disable:4307) // integral constant overflow (oveflow is in a branch not taken when it would overflow) +#pragma warning(disable:4127) // conditional expression is constant +#pragma warning(disable:4702) // Unreachable code (reachability depends on template params) #endif template <unsigned MinBits = 0, unsigned MaxBits = 0, boost::multiprecision::cpp_integer_type SignType = signed_magnitude, cpp_int_check_type Checked = unchecked, class Allocator = typename mpl::if_c<MinBits && (MinBits == MaxBits), void, std::allocator<limb_type> >::type > @@ -226,7 +227,7 @@ public: : m_data(i), m_limbs(1), m_sign(false), m_internal(true) { } BOOST_MP_FORCEINLINE BOOST_CONSTEXPR cpp_int_base(signed_limb_type i)BOOST_NOEXCEPT : m_data(i), m_limbs(1), m_sign(i < 0), m_internal(true) { } -#if defined(BOOST_LITTLE_ENDIAN) +#if defined(BOOST_LITTLE_ENDIAN) && !defined(BOOST_MP_TEST_NO_LE) BOOST_MP_FORCEINLINE BOOST_CONSTEXPR cpp_int_base(double_limb_type i)BOOST_NOEXCEPT : m_data(i), m_limbs(i > max_limb_value ? 2 : 1), m_sign(false), m_internal(true) { } BOOST_MP_FORCEINLINE BOOST_CONSTEXPR cpp_int_base(signed_double_limb_type i)BOOST_NOEXCEPT @@ -444,7 +445,7 @@ public: : m_wrapper(i), m_limbs(1), m_sign(false) {} BOOST_MP_FORCEINLINE BOOST_CONSTEXPR cpp_int_base(signed_limb_type i)BOOST_NOEXCEPT : m_wrapper(limb_type(i < 0 ? static_cast<limb_type>(-static_cast<signed_double_limb_type>(i)) : i)), m_limbs(1), m_sign(i < 0) {} -#if defined(BOOST_LITTLE_ENDIAN) +#if defined(BOOST_LITTLE_ENDIAN) && !defined(BOOST_MP_TEST_NO_LE) BOOST_MP_FORCEINLINE BOOST_CONSTEXPR cpp_int_base(double_limb_type i)BOOST_NOEXCEPT : m_wrapper(i), m_limbs(i > max_limb_value ? 2 : 1), m_sign(false) {} BOOST_MP_FORCEINLINE BOOST_CONSTEXPR cpp_int_base(signed_double_limb_type i)BOOST_NOEXCEPT @@ -595,7 +596,7 @@ public: : m_wrapper(i), m_limbs(1) {} BOOST_MP_FORCEINLINE cpp_int_base(signed_limb_type i)BOOST_MP_NOEXCEPT_IF((Checked == unchecked)) : m_wrapper(limb_type(i < 0 ? static_cast<limb_type>(-static_cast<signed_double_limb_type>(i)) : i)), m_limbs(1) { if(i < 0) negate(); } -#ifdef BOOST_LITTLE_ENDIAN +#if defined(BOOST_LITTLE_ENDIAN) && !defined(BOOST_MP_TEST_NO_LE) BOOST_MP_FORCEINLINE BOOST_CONSTEXPR cpp_int_base(double_limb_type i)BOOST_NOEXCEPT : m_wrapper(i), m_limbs(i > max_limb_value ? 2 : 1) {} BOOST_MP_FORCEINLINE cpp_int_base(signed_double_limb_type i)BOOST_MP_NOEXCEPT_IF((Checked == unchecked)) @@ -773,10 +774,10 @@ public: // template <class SI> BOOST_MP_FORCEINLINE BOOST_CONSTEXPR cpp_int_base(SI i, typename boost::enable_if_c<is_signed<SI>::value && (Checked == unchecked) >::type const* = 0) BOOST_MP_NOEXCEPT_IF(noexcept(std::declval<cpp_int_base>().check_in_range(std::declval<SI>()))) - : m_data(i < 0 ? static_cast<local_limb_type>(static_cast<typename make_unsigned<SI>::type>(boost::multiprecision::detail::unsigned_abs(i)) & limb_mask) : static_cast<local_limb_type>(i)& limb_mask), m_sign(i < 0) {} + : m_data(i < 0 ? static_cast<local_limb_type>(static_cast<typename make_unsigned<SI>::type>(boost::multiprecision::detail::unsigned_abs(i)) & limb_mask) : static_cast<local_limb_type>(i & limb_mask)), m_sign(i < 0) {} template <class SI> BOOST_MP_FORCEINLINE cpp_int_base(SI i, typename boost::enable_if_c<is_signed<SI>::value && (Checked == checked) >::type const* = 0) BOOST_MP_NOEXCEPT_IF(noexcept(std::declval<cpp_int_base>().check_in_range(std::declval<SI>()))) - : m_data(i < 0 ? (static_cast<local_limb_type>(static_cast<typename make_unsigned<SI>::type>(boost::multiprecision::detail::unsigned_abs(i)) & limb_mask)) : static_cast<local_limb_type>(i)& limb_mask), m_sign(i < 0) + : m_data(i < 0 ? (static_cast<local_limb_type>(static_cast<typename make_unsigned<SI>::type>(boost::multiprecision::detail::unsigned_abs(i)) & limb_mask)) : static_cast<local_limb_type>(i & limb_mask)), m_sign(i < 0) { check_in_range(i); } template <class UI> BOOST_MP_FORCEINLINE BOOST_CONSTEXPR cpp_int_base(UI i, typename boost::enable_if_c<is_unsigned<UI>::value && (Checked == unchecked)>::type const* = 0) BOOST_NOEXCEPT @@ -914,6 +915,20 @@ public: // // Direct construction: // +#ifdef __MSVC_RUNTIME_CHECKS + template <class SI> + BOOST_MP_FORCEINLINE BOOST_CONSTEXPR cpp_int_base(SI i, typename boost::enable_if_c<is_signed<SI>::value && (Checked == unchecked) >::type const* = 0) BOOST_NOEXCEPT + : m_data(i < 0 ? (1 + ~static_cast<local_limb_type>(-i & limb_mask)) & limb_mask : static_cast<local_limb_type>(i & limb_mask)) {} + template <class SI> + BOOST_MP_FORCEINLINE cpp_int_base(SI i, typename boost::enable_if_c<is_signed<SI>::value && (Checked == checked) >::type const* = 0) BOOST_MP_NOEXCEPT_IF(noexcept(std::declval<cpp_int_base>().check_in_range(std::declval<SI>()))) + : m_data(i < 0 ? 1 + ~static_cast<local_limb_type>(-i & limb_mask) : static_cast<local_limb_type>(i & limb_mask)) { check_in_range(i); } + template <class UI> + BOOST_MP_FORCEINLINE BOOST_CONSTEXPR cpp_int_base(UI i, typename boost::enable_if_c<is_unsigned<UI>::value && (Checked == unchecked) >::type const* = 0) BOOST_NOEXCEPT + : m_data(static_cast<local_limb_type>(i & limb_mask)) {} + template <class UI> + BOOST_MP_FORCEINLINE cpp_int_base(UI i, typename boost::enable_if_c<is_unsigned<UI>::value && (Checked == checked) >::type const* = 0) BOOST_MP_NOEXCEPT_IF(noexcept(std::declval<cpp_int_base>().check_in_range(std::declval<UI>()))) + : m_data(static_cast<local_limb_type>(i & limb_mask)) { check_in_range(i); } +#else template <class SI> BOOST_MP_FORCEINLINE BOOST_CONSTEXPR cpp_int_base(SI i, typename boost::enable_if_c<is_signed<SI>::value && (Checked == unchecked) >::type const* = 0) BOOST_NOEXCEPT : m_data(i < 0 ? (1 + ~static_cast<local_limb_type>(-i)) & limb_mask : static_cast<local_limb_type>(i) & limb_mask) {} @@ -926,6 +941,7 @@ public: template <class UI> BOOST_MP_FORCEINLINE cpp_int_base(UI i, typename boost::enable_if_c<is_unsigned<UI>::value && (Checked == checked) >::type const* = 0) BOOST_MP_NOEXCEPT_IF(noexcept(std::declval<cpp_int_base>().check_in_range(std::declval<UI>()))) : m_data(static_cast<local_limb_type>(i)) { check_in_range(i); } +#endif template <class F> BOOST_MP_FORCEINLINE cpp_int_base(F i, typename boost::enable_if<is_floating_point<F> >::type const* = 0) BOOST_MP_NOEXCEPT_IF((Checked == unchecked)) : m_data(static_cast<local_limb_type>(std::fabs(i)) & limb_mask) @@ -999,7 +1015,7 @@ public: template <class Arg, class Base> struct is_allowed_cpp_int_base_conversion : public mpl::if_c< is_same<Arg, limb_type>::value || is_same<Arg, signed_limb_type>::value -#ifdef BOOST_LITTLE_ENDIAN +#if defined(BOOST_LITTLE_ENDIAN) && !defined(BOOST_MP_TEST_NO_LE) || is_same<Arg, double_limb_type>::value || is_same<Arg, signed_double_limb_type>::value #endif #if defined(BOOST_MP_USER_DEFINED_LITERALS) @@ -1207,7 +1223,11 @@ private: BOOST_STATIC_ASSERT(sizeof(i) == 2 * sizeof(limb_type)); BOOST_STATIC_ASSERT(base_type::internal_limb_count >= 2); typename base_type::limb_pointer p = this->limbs(); +#ifdef __MSVC_RUNTIME_CHECKS + *p = static_cast<limb_type>(i & ~static_cast<limb_type>(0)); +#else *p = static_cast<limb_type>(i); +#endif p[1] = static_cast<limb_type>(i >> base_type::limb_bits); this->resize(p[1] ? 2 : 1, p[1] ? 2 : 1); this->sign(false); @@ -1222,7 +1242,11 @@ private: s = true; ui = static_cast<double_limb_type>(boost::multiprecision::detail::unsigned_abs(i)); typename base_type::limb_pointer p = this->limbs(); +#ifdef __MSVC_RUNTIME_CHECKS + *p = static_cast<limb_type>(ui & ~static_cast<limb_type>(0)); +#else *p = static_cast<limb_type>(ui); +#endif p[1] = static_cast<limb_type>(ui >> base_type::limb_bits); this->resize(p[1] ? 2 : 1, p[1] ? 2 : 1); this->sign(s); @@ -1368,7 +1392,7 @@ private: } } // - // Exception guarentee: create the result in stack variable "result" + // Exception guarantee: create the result in stack variable "result" // then do a swap at the end. In the event of a throw, *this will // be left unchanged. // @@ -1923,6 +1947,10 @@ struct is_explicitly_convertible<cpp_int_backend<MinBits, MaxBits, SignType, Che } #endif +#ifdef _MSC_VER +#pragma warning(pop) +#endif + }} // namespaces // |