diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-06 10:41:18 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-06 10:43:11 +0900 |
commit | f763a99a501650eff2c60288aa6f10ef916d769e (patch) | |
tree | 02af7e13f9a38c888ebf340fe764cbe7dae99da9 /boost/multiprecision/detail/generic_interconvert.hpp | |
parent | 5cde13f21d36c7224b0e13d11c4b49379ae5210d (diff) | |
download | boost-f763a99a501650eff2c60288aa6f10ef916d769e.tar.gz boost-f763a99a501650eff2c60288aa6f10ef916d769e.tar.bz2 boost-f763a99a501650eff2c60288aa6f10ef916d769e.zip |
Imported Upstream version 1.62.0upstream/1.62.0
Change-Id: I9d4c1ddb7b7d8f0069217ecc582700f9fda6dd4c
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/multiprecision/detail/generic_interconvert.hpp')
-rw-r--r-- | boost/multiprecision/detail/generic_interconvert.hpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/boost/multiprecision/detail/generic_interconvert.hpp b/boost/multiprecision/detail/generic_interconvert.hpp index d1fa028d30..6a840f8544 100644 --- a/boost/multiprecision/detail/generic_interconvert.hpp +++ b/boost/multiprecision/detail/generic_interconvert.hpp @@ -35,36 +35,37 @@ void generic_interconvert(To& to, const From& from, const mpl::int_<number_kind_ using default_ops::eval_right_shift; using default_ops::eval_ldexp; using default_ops::eval_add; + using default_ops::eval_is_zero; // smallest unsigned type handled natively by "From" is likely to be it's limb_type: - typedef typename canonical<unsigned char, From>::type limb_type; + typedef typename canonical<unsigned char, From>::type l_limb_type; // get the corresponding type that we can assign to "To": - typedef typename canonical<limb_type, To>::type to_type; + typedef typename canonical<l_limb_type, To>::type to_type; From t(from); bool is_neg = eval_get_sign(t) < 0; if(is_neg) t.negate(); // Pick off the first limb: - limb_type limb; - limb_type mask = ~static_cast<limb_type>(0); + l_limb_type limb; + l_limb_type mask = static_cast<l_limb_type>(~static_cast<l_limb_type>(0)); From fl; eval_bitwise_and(fl, t, mask); eval_convert_to(&limb, fl); to = static_cast<to_type>(limb); - eval_right_shift(t, std::numeric_limits<limb_type>::digits); + eval_right_shift(t, std::numeric_limits<l_limb_type>::digits); // // Then keep picking off more limbs until "t" is zero: // To l; - unsigned shift = std::numeric_limits<limb_type>::digits; + unsigned shift = std::numeric_limits<l_limb_type>::digits; while(!eval_is_zero(t)) { eval_bitwise_and(fl, t, mask); eval_convert_to(&limb, fl); l = static_cast<to_type>(limb); - eval_right_shift(t, std::numeric_limits<limb_type>::digits); + eval_right_shift(t, std::numeric_limits<l_limb_type>::digits); eval_ldexp(l, l, shift); eval_add(to, l); - shift += std::numeric_limits<limb_type>::digits; + shift += std::numeric_limits<l_limb_type>::digits; } // // Finish off by setting the sign: @@ -310,7 +311,7 @@ typename enable_if_c<is_number<To>::value || is_floating_point<To>::value>::type num = -num; } int denom_bits = msb(denom); - int shift = std::numeric_limits<To>::digits + denom_bits - msb(num) + 1; + int shift = std::numeric_limits<To>::digits + denom_bits - msb(num); if(shift > 0) num <<= shift; else if(shift < 0) @@ -318,7 +319,7 @@ typename enable_if_c<is_number<To>::value || is_floating_point<To>::value>::type Integer q, r; divide_qr(num, denom, q, r); int q_bits = msb(q); - if(q_bits == std::numeric_limits<To>::digits) + if(q_bits == std::numeric_limits<To>::digits - 1) { // // Round up if 2 * r > denom: @@ -334,7 +335,7 @@ typename enable_if_c<is_number<To>::value || is_floating_point<To>::value>::type } else { - BOOST_ASSERT(q_bits == 1 + std::numeric_limits<To>::digits); + BOOST_ASSERT(q_bits == std::numeric_limits<To>::digits); // // We basically already have the rounding info: // |