From c51b2fdcc96ae04a20708dab80ccc93e81b6b0cc Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Thu, 14 Oct 2010 23:21:16 +0000 Subject: [PATCH] changed: small improvements in UInt::Pow() and Big::Pow() git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@325 e52654a7-88a9-db11-a3e9-0013d4bc506e --- ttmath/ttmathbig.h | 15 +++++---------- ttmath/ttmathuint.h | 6 ++---- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/ttmath/ttmathbig.h b/ttmath/ttmathbig.h index 6be5d9b..dc6447e 100644 --- a/ttmath/ttmathbig.h +++ b/ttmath/ttmathbig.h @@ -1571,7 +1571,7 @@ public: return 0; } - Big start(*this), start_temp; + Big start(*this); Big 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 start(*this), start_temp; + Big start(*this); Big result; Big one; - Int 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; diff --git a/ttmath/ttmathuint.h b/ttmath/ttmathuint.h index 25ffbb8..8f26626 100644 --- a/ttmath/ttmathuint.h +++ b/ttmath/ttmathuint.h @@ -2370,7 +2370,7 @@ public: // we don't define zero^zero return 2; - UInt start(*this), start_temp; + UInt start(*this); UInt 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;