From bfdc6d3df34f1a406fa4dc1e7b8c67c9920958ef Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Wed, 25 Mar 2009 01:12:00 +0000 Subject: [PATCH] fixed: Big::Pow(const Big & pow) it's using PowInt() only when pow.exponent is in range (-man*TTMATH_BITS_PER_UINT; 0] previously the powering 'hung' on an input like this: "(1+ 1e-10000) ^ 10e100000000" (the was 10e100000000 iterations in PowInt()) git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@108 e52654a7-88a9-db11-a3e9-0013d4bc506e --- ttmath/ttmathbig.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ttmath/ttmathbig.h b/ttmath/ttmathbig.h index f319f52..c24b6ad 100644 --- a/ttmath/ttmathbig.h +++ b/ttmath/ttmathbig.h @@ -1254,14 +1254,14 @@ public: return 0; } - Big pow_frac( pow ); - pow_frac.RemainFraction(); + if( pow.exponent>-int(man*TTMATH_BITS_PER_UINT) && pow.exponent<=0 ) + { + Big pow_frac( pow ); + pow_frac.RemainFraction(); - if( pow_frac.IsZero() ) - return PowInt( pow ); - - // pow is with fraction (not integer) - // result = e^(pow * ln(this) ) where 'this' must be greater than 0 + if( pow_frac.IsZero() ) + return PowInt( pow ); + } return PowFrac(pow); }