From 00519ff26d8f66170e52f2acf85cb8ac2eb1023c Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Tue, 4 Aug 2009 18:55:18 +0000 Subject: [PATCH] added/fixed: special version of ToString_LogBase() method in single thread environment the previous version of the method didn't store the calculated logarithms git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@184 e52654a7-88a9-db11-a3e9-0013d4bc506e --- ttmath/ttmathbig.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/ttmath/ttmathbig.h b/ttmath/ttmathbig.h index 12eabc4..b65e06a 100644 --- a/ttmath/ttmathbig.h +++ b/ttmath/ttmathbig.h @@ -47,7 +47,10 @@ #include "ttmaththreads.h" #include + +#ifdef TTMATH_MULTITHREADS #include +#endif namespace ttmath { @@ -2980,7 +2983,40 @@ private: } +#ifndef TTMATH_MULTITHREADS + /*! + this method calculates the logarithm of 'base' + it's used in single thread environment + */ + uint ToString_LogBase(uint base, Big & result) + { + TTMATH_ASSERT( base>=2 && base<=16 ) + + // this guardians are initialized before the program runs (static POD types) + static int guardians[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + static Big log_history[15]; + uint index = base - 2; + uint c = 0; + + if( guardians[index] == 0 ) + { + Big base_(base); + c += log_history[index].Ln(base_); + guardians[index] = 1; + } + + result = log_history[index]; + + return (c==0)? 0 : 1; + } + +#else + + /*! + this method calculates the logarithm of 'base' + it's used in multi-thread environment + */ uint ToString_LogBase(uint base, Big & result) { TTMATH_ASSERT( base>=2 && base<=16 ) @@ -3027,6 +3063,7 @@ private: return (c==0)? 0 : 1; } +#endif /*! an auxiliary method for converting into the string (private)