diff --git a/CHANGELOG b/CHANGELOG index 98004be..35755b0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,10 @@ +Version 0.8.4 prerelease (2009.05.01): + * added: UInt::PrintLog(const char * msg, std::ostream & output) + used for debugging purposes by macro TTMATH_LOG(msg) + (it is used in nearly all methods in UInt class) + * added: macro TTMATH_DEBUG_LOG: when defined then TTMATH_LOG() + put some debug information (to std::cout) + Version 0.8.3 (2009.04.06): * fixed: RclMoveAllWords() and RcrMoveAllWords() sometimes didn't return the proper carry, (when 'bits' was greater than or equal to 'value_size') diff --git a/ttmath/ttmath.h b/ttmath/ttmath.h index d50e999..6308fad 100644 --- a/ttmath/ttmath.h +++ b/ttmath/ttmath.h @@ -53,6 +53,13 @@ namespace ttmath { + /* + * + * functions defined here are used only with Big<> types + * + * + */ + /* * diff --git a/ttmath/ttmathbig.h b/ttmath/ttmathbig.h index debcf36..b99bd8b 100644 --- a/ttmath/ttmathbig.h +++ b/ttmath/ttmathbig.h @@ -2255,7 +2255,7 @@ public: a constructor for converting 'uint' to this class */ Big(uint value) - { + { FromUInt(value); } @@ -3367,10 +3367,9 @@ private: // we don't remove any white characters here - // this is only to avoid getting a warning about an uninitialized object - // gcc 4.1.2 reports: 'old_value.info' may be used uninitialized in this function + // this is only to avoid getting a warning about an uninitialized object 'old_value' which GCC reports // (in fact we will initialize it later when the condition 'testing' is fulfilled) - old_value.info = 0; + old_value.SetZero(); power.SetOne(); diff --git a/ttmath/ttmathint.h b/ttmath/ttmathint.h index 2d140e6..b5c5f97 100644 --- a/ttmath/ttmathint.h +++ b/ttmath/ttmathint.h @@ -647,7 +647,7 @@ public: return 0; } - // converting from Int + /*! the default assignment operator @@ -714,7 +714,6 @@ public: } - // converting from UInt /*! this operator converts an UInt type to this class @@ -759,8 +758,8 @@ public: // look that 'size' we still set as 'value_size' and not as u.value_size FromUInt(u); } + - // #ifdef TTMATH_PLATFORM64 diff --git a/ttmath/ttmathtypes.h b/ttmath/ttmathtypes.h index 6ac80d4..42ac7e4 100644 --- a/ttmath/ttmathtypes.h +++ b/ttmath/ttmathtypes.h @@ -64,8 +64,8 @@ */ #define TTMATH_MAJOR_VER 0 #define TTMATH_MINOR_VER 8 -#define TTMATH_REVISION_VER 3 -#define TTMATH_PRERELEASE_VER 0 +#define TTMATH_REVISION_VER 4 +#define TTMATH_PRERELEASE_VER 1 /*! @@ -407,6 +407,19 @@ namespace ttmath #endif + + #ifdef TTMATH_DEBUG_LOG + + #define TTMATH_LOG(msg) \ + PrintLog(msg, std::cout); + + #else + + #define TTMATH_LOG(msg) + + #endif + + } // namespace diff --git a/ttmath/ttmathuint.h b/ttmath/ttmathuint.h index 394d7df..b39a623 100644 --- a/ttmath/ttmathuint.h +++ b/ttmath/ttmathuint.h @@ -118,6 +118,14 @@ public: } + void PrintLog(const char * msg, std::ostream & output) const + { + output << msg << std::endl; + + for(uint i=0 ; i=0 ; --i) table[i] = 0; + + + TTMATH_LOG("UInt32::SetFromTable") } @@ -326,7 +345,8 @@ public: #endif - + TTMATH_LOG("UInt32::Add") + return c; } @@ -427,8 +447,9 @@ public: : "cc", "memory" ); #endif - + TTMATH_LOG("UInt32::AddInt") + return c; } @@ -550,6 +571,7 @@ public: #endif + TTMATH_LOG("UInt32::AddTwoInts") return c; } @@ -646,6 +668,7 @@ public: #endif + TTMATH_LOG("UInt32::Sub") return c; } @@ -745,7 +768,8 @@ public: : "cc", "memory" ); #endif - + + TTMATH_LOG("UInt32::SubInt") return c; } @@ -856,6 +880,7 @@ private: #endif + TTMATH_LOG("UInt32::Rcl2_one") return c; } @@ -931,6 +956,7 @@ private: #endif + TTMATH_LOG("UInt32::Rcr2_one") return c; } @@ -1056,6 +1082,7 @@ private: #endif + TTMATH_LOG("UInt32::Rcl2") return c; } @@ -1187,6 +1214,7 @@ private: #endif + TTMATH_LOG("UInt32::Rcr2") return c; } @@ -1234,6 +1262,8 @@ private: for( ; first>=0 ; --first ) table[first] = mask; } + + TTMATH_LOG("UInt::RclMoveAllWords") } public: @@ -1260,7 +1290,10 @@ public: RclMoveAllWords(rest_bits, last_c, bits, c); if( rest_bits == 0 ) + { + TTMATH_LOG("UInt::Rcl") return last_c; + } // rest_bits is from 1 to TTMATH_BITS_PER_UINT-1 now if( rest_bits == 1 ) @@ -1278,6 +1311,7 @@ public: last_c = Rcl2(rest_bits, c); } + TTMATH_LOG("UInt::Rcl") return last_c; } @@ -1323,6 +1357,8 @@ private: for( ; first0 && table[x1size-1]==0 ; --x1size); if( x1size==0 ) + { + TTMATH_LOG("UInt::MulInt(uint, UInt<>)") return 0; + } for(x1start=0 ; x1start)") + return 0; } @@ -1877,13 +1949,21 @@ public: for(uint i=0; i < value_size*TTMATH_BITS_PER_UINT ; ++i) { if( Add(*this) ) + { + TTMATH_LOG("UInt::Mul1") return 1; + } if( ss1.Rcl(1) ) if( Add(ss2) ) + { + TTMATH_LOG("UInt::Mul1") return 1; + } } + TTMATH_LOG("UInt::Mul1") + return 0; } @@ -1916,6 +1996,8 @@ public: // multiply // (there will not be a carry) result.Mul1( ss2 ); + + TTMATH_LOG("UInt::Mul1Big") } @@ -1947,6 +2029,8 @@ public: if( result.table[i] != 0 ) return 1; + TTMATH_LOG("UInt::Mul2") + return 0; } @@ -1974,7 +2058,10 @@ public: for(x2size=value_size ; x2size>0 && ss2.table[x2size-1]==0 ; --x2size); if( x1size==0 || x2size==0 ) + { + TTMATH_LOG("UInt::Mul2Big") return; + } for(x1start=0 ; x1startSetZero(); SetOne(); + TTMATH_LOG("UInt::Div_StandardTest") return 0; case 3: // 'this' is smaller than v @@ -2164,6 +2259,7 @@ private: *remainder = *this; SetZero(); + TTMATH_LOG("UInt::Div_StandardTest") return 0; case 2: // 'this' is zero @@ -2171,12 +2267,16 @@ private: remainder->SetZero(); SetZero(); + TTMATH_LOG("UInt::Div_StandardTest") return 0; case 1: // v is zero + TTMATH_LOG("UInt::Div_StandardTest") return 1; } + TTMATH_LOG("UInt::Div_StandardTest") + return 2; } @@ -2282,6 +2382,7 @@ private: goto div_a; c = Rcl(1, c); + TTMATH_LOG("UInt::Div1_Calculate") return 0; @@ -2302,6 +2403,8 @@ private: c = Rcl(1, c); c = rest.Add(divisor); + TTMATH_LOG("UInt::Div1_Calculate") + return 0; } @@ -2339,6 +2442,8 @@ public: SetBit(bits_diff); } + TTMATH_LOG("UInt::Div2") + return 0; } @@ -2369,7 +2474,10 @@ private: divisor_table_id, divisor_index); if( status < 2 ) + { + TTMATH_LOG("UInt::Div2_Calculate") return status; + } // here we know that 'this' is greater than divisor // then 'index' is greater or equal 'divisor_index' @@ -2386,6 +2494,8 @@ private: Sub(divisor_copy, 0); + TTMATH_LOG("UInt::Div2_Calculate") + return 2; } @@ -2402,8 +2512,11 @@ private: uint & divisor_table_id, uint & divisor_index) { if( !divisor.FindLeadingBit(divisor_table_id, divisor_index) ) + { // division by zero + TTMATH_LOG("UInt::Div2_FindLeadingBitsAndCheck") return 1; + } if( !FindLeadingBit(table_id, index) ) { @@ -2414,6 +2527,8 @@ private: if( remainder ) remainder->SetZero(); + TTMATH_LOG("UInt::Div2_FindLeadingBitsAndCheck") + return 0; } @@ -2433,6 +2548,8 @@ private: remainder->table[0] = r; } + TTMATH_LOG("UInt::Div2_FindLeadingBitsAndCheck") + return 0; } @@ -2440,9 +2557,14 @@ private: if( Div2_DivisorGreaterOrEqual( divisor, remainder, table_id, index, divisor_table_id, divisor_index) ) + { + TTMATH_LOG("UInt::Div2_FindLeadingBitsAndCheck") return 0; + } + TTMATH_LOG("UInt::Div2_FindLeadingBitsAndCheck") + return 2; } @@ -2465,6 +2587,8 @@ private: SetZero(); + TTMATH_LOG("UInt::Div2_DivisorGreaterOrEqual") + return true; } @@ -2484,6 +2608,8 @@ private: SetZero(); + TTMATH_LOG("UInt::Div2_DivisorGreaterOrEqual") + return true; } else @@ -2496,10 +2622,14 @@ private: SetOne(); + TTMATH_LOG("UInt::Div2_DivisorGreaterOrEqual") + return true; } } + TTMATH_LOG("UInt::Div2_DivisorGreaterOrEqual") + return false; } @@ -2534,6 +2664,8 @@ public: remainder->table[0] = r; } + TTMATH_LOG("UInt::Div3") + return 0; } @@ -2545,6 +2677,8 @@ public: m = m - n; Div3_Division(v, remainder, m, n); + TTMATH_LOG("UInt::Div3") + return 0; } @@ -2599,6 +2733,8 @@ private: Div3_Unnormalize(remainder, n, d); *this = q; + + TTMATH_LOG("UInt::Div3_Division") } @@ -2615,6 +2751,8 @@ private: for( ++i ; i)") return 1; + } 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_LOG("UInt::Pow(UInt<>)") return 1; + } pow.Rcr2_one(0); } *this = result; + TTMATH_LOG("UInt::Pow(UInt<>)") + return 0; } @@ -2815,6 +2972,7 @@ public: if( n >= value_size*TTMATH_BITS_PER_UINT ) { SetZero(); + TTMATH_LOG("UInt::ClearFirstBits") return; } @@ -2828,7 +2986,10 @@ public: } if( n == 0 ) + { + TTMATH_LOG("UInt::ClearFirstBits") return; + } // and then we're clearing one word which has left // mask -- all bits are set to one @@ -2837,6 +2998,8 @@ public: mask = mask << n; (*p) &= mask; + + TTMATH_LOG("UInt::ClearFirstBits") } @@ -2986,9 +3149,14 @@ public: { for( ; i)") return 1; + } } + TTMATH_LOG("UInt::FromUInt(UInt<>)") + return 0; } @@ -3002,6 +3170,8 @@ public: table[i] = 0; table[0] = value; + + TTMATH_LOG("UInt::FromUInt(uint)") } @@ -3015,6 +3185,8 @@ public: { FromUInt(p); + TTMATH_LOG("UInt::operator=(UInt)") + return *this; } @@ -3025,6 +3197,8 @@ public: { FromUInt(p); + TTMATH_LOG("UInt::operator=(UInt<>)") + return *this; } @@ -3036,6 +3210,8 @@ public: { FromUInt(i); + TTMATH_LOG("UInt::operator=(uint)") + return *this; } @@ -3046,6 +3222,8 @@ public: UInt(uint i) { FromUInt(i); + + TTMATH_LOG("UInt::UInt(uint)") } @@ -3066,6 +3244,8 @@ public: { FromUInt(uint(i)); + TTMATH_LOG("UInt::operator=(sint)") + return *this; } @@ -3078,6 +3258,8 @@ public: UInt(sint i) { FromUInt(uint(i)); + + TTMATH_LOG("UInt::UInt(sint)") } /*! @@ -3086,6 +3268,8 @@ public: UInt(const char * s) { FromString(s); + + TTMATH_LOG("UInt::UInt(const char *)") } @@ -3113,6 +3297,8 @@ public: UInt(const UInt & u) { FromUInt(u); + + TTMATH_LOG("UInt::UInt(UInt<>)") } @@ -3125,6 +3311,8 @@ public: { // look that 'size' we still set as 'value_size' and not as u.value_size FromUInt(u); + + TTMATH_LOG("UInt::UInt(UInt)") } @@ -3243,6 +3431,7 @@ public: if( after_source ) *after_source = s; + TTMATH_LOG("UInt::FromString") return (c==0)? 0 : 1; } @@ -3268,6 +3457,8 @@ public: { FromString(s); + TTMATH_LOG("UInt::operator=(const char *)") + return *this; } @@ -3493,6 +3684,8 @@ public: { Sub(p2); + TTMATH_LOG("UInt::operator-=") + return *this; } @@ -3509,6 +3702,8 @@ public: { Add(p2); + TTMATH_LOG("UInt::operator+=") + return *this; } @@ -3527,6 +3722,8 @@ public: { Mul(p2); + TTMATH_LOG("UInt::operator*=") + return *this; } @@ -3545,6 +3742,8 @@ public: { Div(p2); + TTMATH_LOG("UInt::operator/=") + return *this; } @@ -3569,6 +3768,8 @@ public: operator=(remainder); + TTMATH_LOG("UInt::operator%=") + return *this; } @@ -3580,6 +3781,8 @@ public: { AddOne(); + TTMATH_LOG("UInt::operator++") + return *this; } @@ -3592,6 +3795,8 @@ public: AddOne(); + TTMATH_LOG("UInt::operator++(int)") + return temp; } @@ -3600,6 +3805,8 @@ public: { SubOne(); + TTMATH_LOG("UInt::operator--") + return *this; } @@ -3610,6 +3817,8 @@ public: SubOne(); + TTMATH_LOG("UInt::operator--(int)") + return temp; } @@ -3660,6 +3869,8 @@ public: l.FromString(ss); + TTMATH_LOG("UInt::operator>>") + return s; } diff --git a/ttmath/ttmathuint64.h b/ttmath/ttmathuint64.h index c17f333..031dd8a 100644 --- a/ttmath/ttmathuint64.h +++ b/ttmath/ttmathuint64.h @@ -81,6 +81,8 @@ namespace ttmath { FromUInt(uint(i)); + TTMATH_LOG("UInt64::operator=(unsigned int)") + return *this; } @@ -95,6 +97,8 @@ namespace ttmath UInt::UInt(unsigned int i) { FromUInt(uint(i)); + + TTMATH_LOG("UInt64::UInt(unsigned int)") } @@ -111,6 +115,8 @@ namespace ttmath { FromUInt(uint(i)); + TTMATH_LOG("UInt64::operator=(signed int)") + return *this; } @@ -127,6 +133,8 @@ namespace ttmath UInt::UInt(signed int i) { FromUInt(uint(i)); + + TTMATH_LOG("UInt64::UInt(signed int)") } @@ -189,6 +197,8 @@ namespace ttmath // cleaning the rest of the mantissa for( ; i >= 0 ; --i) table[i] = 0; + + TTMATH_LOG("UInt64::SetFromTable") } @@ -249,7 +259,7 @@ namespace ttmath #endif - + TTMATH_LOG("UInt64::Add") return c; } @@ -320,6 +330,7 @@ namespace ttmath #endif + TTMATH_LOG("UInt64::AddInt") return c; } @@ -405,7 +416,8 @@ namespace ttmath #endif - + TTMATH_LOG("UInt64::AddTwoInts") + return c; } @@ -467,6 +479,7 @@ namespace ttmath #endif + TTMATH_LOG("UInt64::Sub") return c; } @@ -534,7 +547,8 @@ namespace ttmath #endif - + TTMATH_LOG("UInt64::SubInt") + return c; } @@ -592,6 +606,7 @@ namespace ttmath #endif + TTMATH_LOG("UInt64::Rcl2_one") return c; } @@ -646,6 +661,7 @@ namespace ttmath #endif + TTMATH_LOG("UInt64::Rcr2_one") return c; } @@ -725,6 +741,7 @@ namespace ttmath #endif + TTMATH_LOG("UInt64::Rcl2") return c; } @@ -807,6 +824,7 @@ namespace ttmath #endif + TTMATH_LOG("UInt64::Rcr2") return c; }