From 69f065245eab8d03300e1b64200df9616846c082 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Wed, 18 Aug 2010 23:31:58 +0000 Subject: [PATCH] fixed: Big::Add sometimes incorrectly rounded the last bit from mantissa (when exp_offset == mantissa_size_in_bits ) the rounding_up was always false git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@303 e52654a7-88a9-db11-a3e9-0013d4bc506e --- ttmath/ttmathbig.h | 11 +++++------ ttmath/ttmathuint.h | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) 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) {