fixed: in Big::ToString_CreateNewMantissaAndExponent() changed the formula:

new_exp_ = [log base (2^exponent)] + 1
       now the part '+ 1' is only made when the logarithm is positive and with fraction
       if the value is negative we can only skip the fraction, previously
       we lost some last digits from the new mantissa
       
       Consider this binary value (32 bit mantissa):
       (bin)1.0000000000000000000000000000011
       previously ToString() gave 1, now we have: 1.000000001



git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@274 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2009-12-28 15:41:28 +00:00
parent 0ada20b4cb
commit 39db6fc469
2 changed files with 26 additions and 6 deletions

View File

@ -1,4 +1,4 @@
Version 0.9.1 prerelease (2009.12.25): Version 0.9.1 prerelease (2009.12.28):
* fixed: the parser didn't use characters for changing the base (# and &) * fixed: the parser didn't use characters for changing the base (# and &)
those characters were skipped those characters were skipped
(this bug was introduced in 0.9.0) (this bug was introduced in 0.9.0)
@ -6,6 +6,14 @@ Version 0.9.1 prerelease (2009.12.25):
operator ^ (powering) is right-associative: operator ^ (powering) is right-associative:
sample: 2^3^4 is equal 2^(3^4) and it is: 2.41e+24 sample: 2^3^4 is equal 2^(3^4) and it is: 2.41e+24
previously was: 2^3^4 = (2^3)^4 = 4096 previously was: 2^3^4 = (2^3)^4 = 4096
* fixed: in Big::ToString_CreateNewMantissaAndExponent() changed the formula:
new_exp_ = [log base (2^exponent)] + 1
now the part '+ 1' is only made when the logarithm is positive and with fraction
if the value is negative we can only skip the fraction, previously
we lost some last digits from the new mantissa
Consider this binary value (32 bit mantissa):
(bin)1.0000000000000000000000000000011
previously ToString() gave 1, now we have: 1.000000001
* added: IEEE 754 half-to-even rounding (bankers' rounding) to the following * added: IEEE 754 half-to-even rounding (bankers' rounding) to the following
floating point algorithms: Big::Add, Big::Sub, Big::Mul, Big::Div floating point algorithms: Big::Add, Big::Sub, Big::Mul, Big::Div
* added: to Big::ToString() - additional rounding when conv.base_round is used * added: to Big::ToString() - additional rounding when conv.base_round is used

View File

@ -3312,8 +3312,11 @@ private:
2^exponent <= base^new_exp 2^exponent <= base^new_exp
new_exp >= log base (2^exponent) <- logarithm with the base 'base' from (2^exponent) new_exp >= log base (2^exponent) <- logarithm with the base 'base' from (2^exponent)
but we need 'new'exp' as integer then we take: but we need new_exp as integer then we test:
new_exp = [log base (2^exponent)] + 1 <- where [x] means integer value from x if new_exp is greater than zero and with fraction we add one to new_exp
new_exp = new_exp + 1 (if new_exp>0 and with fraction)
and at the end we take the integer part:
new_exp = int(new_exp)
*/ */
template<class string_type, class char_type> template<class string_type, class char_type>
uint ToString_CreateNewMantissaAndExponent( string_type & new_man, const Conv & conv, uint ToString_CreateNewMantissaAndExponent( string_type & new_man, const Conv & conv,
@ -3351,12 +3354,21 @@ private:
temp.mantissa.SetOne(); temp.mantissa.SetOne();
c += temp.Standardizing(); c += temp.Standardizing();
// new_exp_ = [log base (2^exponent)] + 1 // new_exp_ = log base (2^exponent)
// if new_exp_ is positive and with fraction then we add one
Big<exp+1,man> new_exp_; Big<exp+1,man> new_exp_;
c += new_exp_.ToString_Log(temp, conv.base); // this logarithm isn't very complicated c += new_exp_.ToString_Log(temp, conv.base); // this logarithm isn't very complicated
if( !new_exp_.IsSign() && !new_exp_.IsInteger() )
{
// new_exp_ > 0 and with fraction
temp.SetOne();
c += new_exp_.Add( temp );
}
// new_exp_ = int(new_exp_)
new_exp_.SkipFraction(); new_exp_.SkipFraction();
temp.SetOne();
c += new_exp_.Add( temp );
// because 'base^new_exp' is >= '2^exponent' then // because 'base^new_exp' is >= '2^exponent' then
// because base is >= 2 then we've got: // because base is >= 2 then we've got: