diff options
Diffstat (limited to 'boost/multiprecision/cpp_bin_float.hpp')
-rw-r--r-- | boost/multiprecision/cpp_bin_float.hpp | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/boost/multiprecision/cpp_bin_float.hpp b/boost/multiprecision/cpp_bin_float.hpp index 9a4ceff587..4c00799843 100644 --- a/boost/multiprecision/cpp_bin_float.hpp +++ b/boost/multiprecision/cpp_bin_float.hpp @@ -21,7 +21,7 @@ enum digit_base_type #ifdef BOOST_MSVC #pragma warning(push) -#pragma warning(disable:4522) // multiple assignment operators specified +#pragma warning(disable:4522 6326) // multiple assignment operators specified, comparison of two constants #endif namespace detail{ @@ -37,7 +37,7 @@ template <unsigned Digits, digit_base_type DigitBase = digit_base_10, class Allo class cpp_bin_float { public: - static const unsigned bit_count = DigitBase == digit_base_2 ? Digits : (Digits * 1000uL) / 301uL + ((Digits * 1000uL) % 301 ? 2u : 1u); + static const unsigned bit_count = DigitBase == digit_base_2 ? Digits : (Digits * 1000uL) / 301uL + (((Digits * 1000uL) % 301) ? 2u : 1u); typedef cpp_int_backend<is_void<Allocator>::value ? bit_count : 0, bit_count, is_void<Allocator>::value ? unsigned_magnitude : signed_magnitude, unchecked, Allocator> rep_type; typedef cpp_int_backend<is_void<Allocator>::value ? 2 * bit_count : 0, 2 * bit_count, is_void<Allocator>::value ? unsigned_magnitude : signed_magnitude, unchecked, Allocator> double_rep_type; @@ -67,9 +67,9 @@ private: exponent_type m_exponent; bool m_sign; public: - cpp_bin_float() BOOST_NOEXCEPT_IF(noexcept(rep_type())) : m_data(), m_exponent(exponent_nan), m_sign(false) {} + cpp_bin_float() BOOST_MP_NOEXCEPT_IF(noexcept(rep_type())) : m_data(), m_exponent(exponent_nan), m_sign(false) {} - cpp_bin_float(const cpp_bin_float &o) BOOST_NOEXCEPT_IF(noexcept(rep_type(std::declval<const rep_type&>()))) + cpp_bin_float(const cpp_bin_float &o) BOOST_MP_NOEXCEPT_IF(noexcept(rep_type(std::declval<const rep_type&>()))) : m_data(o.m_data), m_exponent(o.m_exponent), m_sign(o.m_sign) {} template <unsigned D, digit_base_type B, class A, class E, E MinE, E MaxE> @@ -104,7 +104,7 @@ public: this->assign_float(f); } - cpp_bin_float& operator=(const cpp_bin_float &o) BOOST_NOEXCEPT_IF(noexcept(std::declval<rep_type&>() = std::declval<const rep_type&>())) + cpp_bin_float& operator=(const cpp_bin_float &o) BOOST_MP_NOEXCEPT_IF(noexcept(std::declval<rep_type&>() = std::declval<const rep_type&>())) { m_data = o.m_data; m_exponent = o.m_exponent; @@ -773,6 +773,10 @@ inline typename enable_if_c<is_signed<S>::value>::type eval_multiply(cpp_bin_flo template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE> inline void eval_divide(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> &res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> &u, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> &v) { +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:6326) // comparison of two constants +#endif using default_ops::eval_subtract; using default_ops::eval_qr; using default_ops::eval_bit_test; @@ -882,7 +886,7 @@ inline void eval_divide(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, Mi // how we'll be rounding. // BOOST_ASSERT((eval_msb(q) == cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - 1)); - static const unsigned lshift = cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count < limb_bits ? 2 : limb_bits; + static const unsigned lshift = (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count < limb_bits) ? 2 : limb_bits; eval_left_shift(q, lshift); res.exponent() -= lshift; eval_left_shift(r, 1u); @@ -893,6 +897,9 @@ inline void eval_divide(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, Mi q.limbs()[0] |= (static_cast<limb_type>(1u) << (lshift - 1)) + static_cast<limb_type>(1u); } copy_and_round(res, q); +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif } template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE> @@ -904,6 +911,10 @@ inline void eval_divide(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, Mi template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class U> inline typename enable_if_c<is_unsigned<U>::value>::type eval_divide(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> &res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> &u, const U &v) { +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:6326) // comparison of two constants +#endif using default_ops::eval_subtract; using default_ops::eval_qr; using default_ops::eval_bit_test; @@ -1000,6 +1011,9 @@ inline typename enable_if_c<is_unsigned<U>::value>::type eval_divide(cpp_bin_flo q.limbs()[0] |= (static_cast<limb_type>(1u) << (lshift - 1)) + static_cast<limb_type>(1u); } copy_and_round(res, q); +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif } template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE, class U> @@ -1045,7 +1059,7 @@ inline bool eval_eq(const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, } template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE> -inline void eval_convert_to(long long *res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> &arg) +inline void eval_convert_to(boost::long_long_type *res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> &arg) { switch(arg.exponent()) { @@ -1055,7 +1069,7 @@ inline void eval_convert_to(long long *res, const cpp_bin_float<Digits, DigitBas case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan: BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert NaN to integer.")); case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity: - *res = (std::numeric_limits<long long>::max)(); + *res = (std::numeric_limits<boost::long_long_type>::max)(); if(arg.sign()) *res = -*res; return; @@ -1068,14 +1082,14 @@ inline void eval_convert_to(long long *res, const cpp_bin_float<Digits, DigitBas *res = 0; return; } - if(arg.sign() && (arg.compare((std::numeric_limits<long long>::min)()) <= 0)) + if(arg.sign() && (arg.compare((std::numeric_limits<boost::long_long_type>::min)()) <= 0)) { - *res = (std::numeric_limits<long long>::min)(); + *res = (std::numeric_limits<boost::long_long_type>::min)(); return; } - else if(!arg.sign() && (arg.compare((std::numeric_limits<long long>::max)()) >= 0)) + else if(!arg.sign() && (arg.compare((std::numeric_limits<boost::long_long_type>::max)()) >= 0)) { - *res = (std::numeric_limits<long long>::max)(); + *res = (std::numeric_limits<boost::long_long_type>::max)(); return; } eval_right_shift(man, shift); @@ -1087,7 +1101,7 @@ inline void eval_convert_to(long long *res, const cpp_bin_float<Digits, DigitBas } template <unsigned Digits, digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE> -inline void eval_convert_to(unsigned long long *res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> &arg) +inline void eval_convert_to(boost::ulong_long_type *res, const cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> &arg) { switch(arg.exponent()) { @@ -1097,7 +1111,7 @@ inline void eval_convert_to(unsigned long long *res, const cpp_bin_float<Digits, case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan: BOOST_THROW_EXCEPTION(std::runtime_error("Could not convert NaN to integer.")); case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity: - *res = (std::numeric_limits<unsigned long long>::max)(); + *res = (std::numeric_limits<boost::ulong_long_type>::max)(); return; } typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::rep_type man(arg.bits()); @@ -1110,8 +1124,8 @@ inline void eval_convert_to(unsigned long long *res, const cpp_bin_float<Digits, } else if(shift < 0) { - // TODO: what if we have fewer cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count than a long long? - *res = (std::numeric_limits<long long>::max)(); + // TODO: what if we have fewer cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count than a boost::long_long_type? + *res = (std::numeric_limits<boost::long_long_type>::max)(); return; } eval_right_shift(man, shift); @@ -1462,9 +1476,9 @@ public: return -(max)(); } BOOST_STATIC_CONSTEXPR int digits = boost::multiprecision::cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count; - BOOST_STATIC_CONSTEXPR int digits10 = digits * 301 / 1000; + BOOST_STATIC_CONSTEXPR int digits10 = (digits - 1) * 301 / 1000; // Is this really correct??? - BOOST_STATIC_CONSTEXPR int max_digits10 = digits10 + 2; + BOOST_STATIC_CONSTEXPR int max_digits10 = (digits * 301 / 1000) + 2; BOOST_STATIC_CONSTEXPR bool is_signed = true; BOOST_STATIC_CONSTEXPR bool is_integer = false; BOOST_STATIC_CONSTEXPR bool is_exact = false; |