From 3b9399c521343719137ec09bdca86fe68a1ce034 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sun, 29 Jun 2014 10:34:45 +0100 Subject: [PATCH] Fix rounding bug in cpp_bin_float - in the case that the remainder is zero, we may still have a tie if the extra bit in the quotient is one. --- include/boost/multiprecision/cpp_bin_float.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/boost/multiprecision/cpp_bin_float.hpp b/include/boost/multiprecision/cpp_bin_float.hpp index 97b7174b..0f97bdf3 100644 --- a/include/boost/multiprecision/cpp_bin_float.hpp +++ b/include/boost/multiprecision/cpp_bin_float.hpp @@ -855,11 +855,12 @@ inline void eval_divide(cpp_bin_float::bit_count+1 bits, // so we already have rounding info, - // we just need to changes things if the last bit is 1 and the - // remainder is non-zero (ie we do not have a tie). + // we just need to changes things if the last bit is 1 and either the + // remainder is non-zero (ie we do not have a tie) or the quotient would + // be odd if it were shifted to the correct number of bits (ie a tiebreak). // BOOST_ASSERT((eval_msb(q) == cpp_bin_float::bit_count)); - if((q.limbs()[0] & 1u) && eval_get_sign(r)) + if((q.limbs()[0] & 1u) && (eval_get_sign(r) || (q.limbs()[0] & 2u))) { eval_increment(q); }