From b6fe168e3c2b62235f3dc8c12456b67d31f23f50 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sat, 18 Sep 2010 01:35:16 +0000 Subject: [PATCH] added: Big::operator++() Big::operator++(int) Big::operator--() Big::operator--(int) Big::AddOne() Big::SubOne() changed: Big::SetOne() a little faster now git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@310 e52654a7-88a9-db11-a3e9-0013d4bc506e --- CHANGELOG | 8 +++-- ttmath/ttmathbig.h | 80 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 83 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index bca5425..670d051 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -Version 0.9.2 prerelease (2010.09.15): +Version 0.9.2 prerelease (2010.09.18): * 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) @@ -18,7 +18,11 @@ Version 0.9.2 prerelease (2010.09.15): Big::operator|=() Big::operator^() Big::operator^=() - for Big<> we do not define bitwise neg + for Big<> we do not define bitwise neg + Big::operator++() + Big::operator++(int) + Big::operator--() + Big::operator--(int) * added: macro TTMATH_DONT_USE_WCHAR if defined then the library does not use wide characters (wchar_t, std::wstring, ...) this is a workaround for some compilers diff --git a/ttmath/ttmathbig.h b/ttmath/ttmathbig.h index 5618a5f..a6d181c 100644 --- a/ttmath/ttmathbig.h +++ b/ttmath/ttmathbig.h @@ -270,7 +270,12 @@ public: */ void SetOne() { - FromUInt(1); + info = 0; + mantissa.SetZero(); + mantissa.table[man-1] = TTMATH_UINT_HIGHEST_BIT; + exponent = -sint(man * TTMATH_BITS_PER_UINT - 1); + + // don't have to Standardize() - the last bit is set } @@ -279,7 +284,7 @@ public: */ void Set05() { - FromUInt(1); + SetOne(); exponent.SubOne(); } @@ -693,7 +698,7 @@ public: } else if( IsZero() ) - SetZero(); + SetZero(); // !! is nedeed here? else SetOne(); } @@ -792,6 +797,33 @@ private: * */ + + /*! + this method adds one to the existing value + */ + uint AddOne() + { + Big one; + + one.SetOne(); + + return Add(one); + } + + + /*! + this method subtracts one from the existing value + */ + uint SubOne() + { + Big one; + + one.SetOne(); + + return Sub(one); + } + + private: @@ -4966,6 +4998,48 @@ public: } + /*! + Prefix operator e.g ++variable + */ + Big & operator++() + { + AddOne(); + + return *this; + } + + + /*! + Postfix operator e.g variable++ + */ + Big operator++(int) + { + Big temp( *this ); + + AddOne(); + + return temp; + } + + + Big & operator--() + { + SubOne(); + + return *this; + } + + + Big operator--(int) + { + Big temp( *this ); + + SubOne(); + + return temp; + } + + /*! *