diff --git a/ttmath/ttmathbig.h b/ttmath/ttmathbig.h index 7b4fb4f..be1e376 100644 --- a/ttmath/ttmathbig.h +++ b/ttmath/ttmathbig.h @@ -819,8 +819,7 @@ private: */ uint AddMantissas( Big & ss2, bool & last_bit_set, - bool & rest_zero, - bool & rounding_up) + bool & rest_zero) { uint c = 0; @@ -835,8 +834,6 @@ private: last_bit_set = mantissa.Rcr(1,1); c += exponent.AddOne(); } - - rounding_up = true; } else { @@ -890,11 +887,13 @@ public: if( ss2.IsZero() ) return 0; - last_bit_set = rest_zero = do_adding = do_rounding = rounding_up = false; + last_bit_set = rest_zero = do_adding = do_rounding = false; + rounding_up = (IsSign() == ss2.IsSign()); + AddCheckExponents(ss2, exp_offset, last_bit_set, rest_zero, do_adding, do_rounding); if( do_adding ) - c += AddMantissas(ss2, last_bit_set, rest_zero, rounding_up); + c += AddMantissas(ss2, last_bit_set, rest_zero); if( !round || !last_bit_set ) do_rounding = false; diff --git a/ttmath/ttmathuint.h b/ttmath/ttmathuint.h index 5041c8b..fa2ab87 100644 --- a/ttmath/ttmathuint.h +++ b/ttmath/ttmathuint.h @@ -1965,6 +1965,7 @@ public: this algorithm is described in the following book: "The art of computer programming 2" (4.3.1 page 272) Donald E. Knuth + !! give the description here (from the book) */ uint Div3(const UInt & v, UInt * remainder = 0) {