changed: small improvements in UInt::Pow() and Big::Pow()

git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@325 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2010-10-14 23:21:16 +00:00
parent 84f34ebe52
commit c51b2fdcc9
2 changed files with 7 additions and 14 deletions

View File

@ -1571,7 +1571,7 @@ public:
return 0;
}
Big<exp, man> start(*this), start_temp;
Big<exp, man> start(*this);
Big<exp, man> result;
result.SetOne();
uint c = 0;
@ -1586,8 +1586,7 @@ public:
if( pow.IsZero() )
break;
start_temp = start;
c += start.Mul(start_temp);
c += start.Mul(start);
}
*this = result;
@ -1665,13 +1664,10 @@ public:
if( pow.IsSign() )
pow.Abs();
Big<exp, man> start(*this), start_temp;
Big<exp, man> start(*this);
Big<exp, man> result;
Big<exp, man> one;
Int<exp> e_one;
uint c = 0;
e_one.SetOne();
one.SetOne();
result = one;
@ -1680,13 +1676,12 @@ public:
if( pow.Mod2() )
c += result.Mul(start);
c += pow.exponent.Sub( e_one ); // !! may use SubOne() here?
c += pow.exponent.SubOne();
if( pow < one )
break;
start_temp = start;
c += start.Mul(start_temp);
c += start.Mul(start);
}
*this = result;

View File

@ -2370,7 +2370,7 @@ public:
// we don't define zero^zero
return 2;
UInt<value_size> start(*this), start_temp;
UInt<value_size> start(*this);
UInt<value_size> result;
result.SetOne();
uint c = 0;
@ -2384,9 +2384,7 @@ public:
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)
c += start.Mul(start_temp);
c += start.Mul(start);
}
*this = result;