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
This commit is contained in:
parent
c65dac524a
commit
69f065245e
|
@ -819,8 +819,7 @@ private:
|
||||||
*/
|
*/
|
||||||
uint AddMantissas( Big<exp, man> & ss2,
|
uint AddMantissas( Big<exp, man> & ss2,
|
||||||
bool & last_bit_set,
|
bool & last_bit_set,
|
||||||
bool & rest_zero,
|
bool & rest_zero)
|
||||||
bool & rounding_up)
|
|
||||||
{
|
{
|
||||||
uint c = 0;
|
uint c = 0;
|
||||||
|
|
||||||
|
@ -835,8 +834,6 @@ private:
|
||||||
last_bit_set = mantissa.Rcr(1,1);
|
last_bit_set = mantissa.Rcr(1,1);
|
||||||
c += exponent.AddOne();
|
c += exponent.AddOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
rounding_up = true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -890,11 +887,13 @@ public:
|
||||||
if( ss2.IsZero() )
|
if( ss2.IsZero() )
|
||||||
return 0;
|
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);
|
AddCheckExponents(ss2, exp_offset, last_bit_set, rest_zero, do_adding, do_rounding);
|
||||||
|
|
||||||
if( do_adding )
|
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 )
|
if( !round || !last_bit_set )
|
||||||
do_rounding = false;
|
do_rounding = false;
|
||||||
|
|
|
@ -1965,6 +1965,7 @@ public:
|
||||||
this algorithm is described in the following book:
|
this algorithm is described in the following book:
|
||||||
"The art of computer programming 2" (4.3.1 page 272)
|
"The art of computer programming 2" (4.3.1 page 272)
|
||||||
Donald E. Knuth
|
Donald E. Knuth
|
||||||
|
!! give the description here (from the book)
|
||||||
*/
|
*/
|
||||||
uint Div3(const UInt<value_size> & v, UInt<value_size> * remainder = 0)
|
uint Div3(const UInt<value_size> & v, UInt<value_size> * remainder = 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue