fixed: powering algorithm in:
UInt::Pow(UInt<value_size> pow) Big::Pow(UInt<pow_size> pow) Big::PowUInt(Big<exp, man> pow) when 'pow' was sufficient large the algorithm returned carry but the result could have been calculated correctly git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@213 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
462ff7cc65
commit
af4fbf3098
|
@ -1,4 +1,4 @@
|
|||
Version 0.9.0 prerelease (2009.10.13):
|
||||
Version 0.9.0 prerelease (2009.10.16):
|
||||
* fixed: Big::operator>>(std::istream&, Big<> &) didn't recognize values
|
||||
in scientific mode (with 'e' character)
|
||||
* fixed: UInt::SetBitInWord(uint & value, uint bit) set 1 if the bit was
|
||||
|
@ -9,6 +9,12 @@ Version 0.9.0 prerelease (2009.10.13):
|
|||
* fixed: UInt::AddVector() and UInt::SubVector() didn't want to compile
|
||||
when macro TTMATH_NOASM was defined
|
||||
* fixed: buffer overflow in Big::ToInt(Int<int_size> & result)
|
||||
* fixed: powering algorithm in:
|
||||
UInt::Pow(UInt<value_size> pow)
|
||||
Big::Pow(UInt<pow_size> pow)
|
||||
Big::PowUInt(Big<exp, man> pow)
|
||||
when 'pow' was sufficient large the algorithm returned carry
|
||||
but the result could have been calculated correctly
|
||||
* added: support for wide characters (wchar_t, std::wstring)
|
||||
* added: Big::IsInteger()
|
||||
returns true if the value is integer (without fraction)
|
||||
|
|
|
@ -1258,15 +1258,18 @@ public:
|
|||
result.SetOne();
|
||||
uint c = 0;
|
||||
|
||||
while( !c && !pow.IsZero() )
|
||||
while( !c )
|
||||
{
|
||||
if( pow.table[0] & 1 )
|
||||
c += result.Mul(start);
|
||||
|
||||
pow.Rcr(1);
|
||||
|
||||
if( pow.IsZero() )
|
||||
break;
|
||||
|
||||
start_temp = start;
|
||||
c += start.Mul(start_temp);
|
||||
|
||||
pow.Rcr(1);
|
||||
}
|
||||
|
||||
*this = result;
|
||||
|
@ -1374,15 +1377,18 @@ public:
|
|||
one.SetOne();
|
||||
result = one;
|
||||
|
||||
while( !c && pow >= one )
|
||||
while( !c )
|
||||
{
|
||||
if( pow.Mod2() )
|
||||
c += result.Mul(start);
|
||||
|
||||
c += pow.exponent.Sub( e_one );
|
||||
|
||||
if( pow < one )
|
||||
break;
|
||||
|
||||
start_temp = start;
|
||||
c += start.Mul(start_temp);
|
||||
|
||||
c += pow.exponent.Sub( e_one );
|
||||
}
|
||||
|
||||
*this = result;
|
||||
|
|
|
@ -514,7 +514,7 @@ public:
|
|||
return Pow2(pow);
|
||||
|
||||
if( UInt<value_size>::IsZero() )
|
||||
// if 'p' is negative then
|
||||
// if 'pow' is negative then
|
||||
// 'this' must be different from zero
|
||||
return 2;
|
||||
|
||||
|
|
|
@ -2228,32 +2228,27 @@ public:
|
|||
UInt<value_size> start(*this), start_temp;
|
||||
UInt<value_size> result;
|
||||
result.SetOne();
|
||||
uint c = 0;
|
||||
|
||||
while( !pow.IsZero() )
|
||||
while( !c )
|
||||
{
|
||||
if( pow.table[0] & 1 )
|
||||
if( result.Mul(start) )
|
||||
{
|
||||
TTMATH_LOGC("UInt::Pow(UInt<>)", 1)
|
||||
return 1;
|
||||
}
|
||||
c += result.Mul(start);
|
||||
|
||||
pow.Rcr2_one(0);
|
||||
if( pow.IsZero() )
|
||||
break;
|
||||
|
||||
start_temp = start;
|
||||
// in the second Mul algorithm we can use start.Mul(start) directly (there is no TTMATH_ASSERT_REFERENCE there)
|
||||
if( start.Mul(start_temp) )
|
||||
{
|
||||
TTMATH_LOGC("UInt::Pow(UInt<>)", 1)
|
||||
return 1;
|
||||
}
|
||||
|
||||
pow.Rcr2_one(0);
|
||||
c += start.Mul(start_temp);
|
||||
}
|
||||
|
||||
*this = result;
|
||||
|
||||
TTMATH_LOGC("UInt::Pow(UInt<>)", 0)
|
||||
TTMATH_LOGC("UInt::Pow(UInt<>)", c)
|
||||
|
||||
return 0;
|
||||
return (c==0)? 0 : 1;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue