diff --git a/CHANGELOG b/CHANGELOG index 3b1f9f4..bca5425 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -Version 0.9.2 prerelease (2010.09.05): +Version 0.9.2 prerelease (2010.09.15): * fixed: Big::Add() sometimes incorrectly rounded the last bit from its mantissa * fixed: Big::BigAnd() Big::BigOr() Big::BigXor() should have set NaN when the argument was negative (they only returned 2) @@ -29,6 +29,11 @@ Version 0.9.2 prerelease (2010.09.05): * added: void UInt::Swap(UInt & ss2) void Big::Swap(UInt & ss2) method for swapping this for an argument + * added: macro TTMATH_BIG_DEFAULT_CLEAR + when defined the default constructor from Big<> clears its mantissa and exponent + Big<1, 2> var; + var.mantissa and var.exponent will be set to zero + (but var has the NaN flag set too - it is not zero value, this is mainly for debug purposes) * changed: now asm version is available only on x86 and amd64 (and only for GCC and MS VC compilers) * removed: macro TTMATH_RELEASE diff --git a/ttmath/ttmath.h b/ttmath/ttmath.h index 8bd24f5..37c971f 100644 --- a/ttmath/ttmath.h +++ b/ttmath/ttmath.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2009, Tomasz Sowa + * Copyright (c) 2006-2010, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -273,12 +273,16 @@ namespace ttmath template ValueType Log(const ValueType & x, const ValueType & base, ErrorCode * err = 0) { - if( x.IsNan() || base.IsNan() ) + if( x.IsNan() ) { - if( err ) - *err = err_improper_argument; + if( err ) *err = err_improper_argument; + return x; + } - return ValueType(); // default NaN + if( base.IsNan() ) + { + if( err ) *err = err_improper_argument; + return base; } ValueType result; @@ -523,7 +527,7 @@ namespace ttmath if( err ) *err = err_improper_argument; - return result; // NaN is set by default + return x; } if( err ) @@ -854,7 +858,7 @@ namespace ttmath if( err ) *err = err_improper_argument; - return result; // NaN is set by default + return x; } if( x.GreaterWithoutSignThan(one) ) @@ -1080,7 +1084,7 @@ namespace ttmath bool change_sign = false; if( x.IsNan() ) - return result; // NaN is set by default + return x; // if x is negative we're using the formula: // atan(-x) = -atan(x) @@ -1548,7 +1552,7 @@ namespace ttmath if( err ) *err = err_improper_argument; - return result; // NaN is set by default + return x; } result = x; @@ -1584,7 +1588,7 @@ namespace ttmath if( err ) *err = err_improper_argument; - return result; // NaN is set by default + return x; } result = 180; @@ -1629,7 +1633,9 @@ namespace ttmath if( err ) *err = err_improper_argument; - return delimiter ; // NaN is set by default + delimiter.SetZeroNan(); // not needed, only to get rid of GCC warning about an uninitialized variable + + return delimiter; } multipler = 60; @@ -1683,7 +1689,7 @@ namespace ttmath if( err ) *err = err_improper_argument; - return result; // NaN is set by default + return x; } result = x; @@ -1719,7 +1725,7 @@ namespace ttmath if( err ) *err = err_improper_argument; - return result; // NaN is set by default + return x; } result = 200; @@ -1751,7 +1757,7 @@ namespace ttmath if( err ) *err = err_improper_argument; - return result; // NaN is set by default + return x; } result = x; @@ -1801,7 +1807,7 @@ namespace ttmath if( err ) *err = err_improper_argument; - return result; // NaN is set by default + return x; } result = x; @@ -1842,7 +1848,9 @@ namespace ttmath if( err ) *err = err_improper_argument; - return ValueType(); // NaN is set by default + x.SetNan(); + + return x; } uint c = x.Sqrt(); @@ -2065,7 +2073,9 @@ namespace ttmath if( err ) *err = err_improper_argument; - return ValueType(); // NaN is set by default + x.SetNan(); + + return x; } if( RootCheckIndexSign(x, index, err) ) return x; @@ -2154,7 +2164,9 @@ namespace ttmath if( err ) *err = err_improper_argument; - return ValueType(); // NaN is set by default + a.SetNan(); + + return a; } uint c = a.Mod(b); @@ -2652,7 +2664,7 @@ namespace ttmath if( err ) *err = err_improper_argument; - return result; // NaN is set by default + return n; } if( cgamma.history.Get(n, result, err_tmp) ) @@ -2731,7 +2743,9 @@ namespace ttmath if( err ) *err = err_improper_argument; - return result; // NaN set by default + x.SetNan(); + + return x; } one.SetOne(); diff --git a/ttmath/ttmathbig.h b/ttmath/ttmathbig.h index 48f5f48..5618a5f 100644 --- a/ttmath/ttmathbig.h +++ b/ttmath/ttmathbig.h @@ -294,6 +294,17 @@ public: } + /*! + this method sets NaN flag (Not a Number) + also clears the mantissa and exponent (similarly as it would be a zero value) + */ + void SetZeroNan() + { + SetZero(); + SetNan(); + } + + /*! this method swappes this for an argument */ @@ -3001,17 +3012,26 @@ public: /*! a default constructor - we don't set any of the members to zero + by default we don't set any of the members to zero only NaN flag is set + + if you want the mantissa and exponent to be set to zero + define TTMATH_BIG_DEFAULT_CLEAR macro + (useful for debug purposes) */ Big() { - info = TTMATH_BIG_NAN; + #ifdef TTMATH_BIG_DEFAULT_CLEAR - /* - we're directly setting 'info' (instead of calling SetNan()) - in order to get rid of a warning saying that 'info' is uninitialized - */ + SetZeroNan(); + + #else + + info = TTMATH_BIG_NAN; + // we're directly setting 'info' (instead of calling SetNan()) + // in order to get rid of a warning saying that 'info' is uninitialized + + #endif } @@ -3034,7 +3054,7 @@ public: return *this; } - + /*! a constructor for copying from another object of this class diff --git a/ttmath/ttmathuint.h b/ttmath/ttmathuint.h index 9b55bcb..8eda5bd 100644 --- a/ttmath/ttmathuint.h +++ b/ttmath/ttmathuint.h @@ -1375,8 +1375,9 @@ private: TTMATH_ASSERT( z1_size <= first_size*3 ) for(i=z1_size ; i