From c65dac524a56321616a3a78106ebdad95376e5da Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Wed, 18 Aug 2010 18:09:16 +0000 Subject: [PATCH] fixed: Big::BigAnd() Big::BigOr() Big::BigXor() should have set NaN when the argument was negative (they only returned 2) added: some missing operators UInt::operator~() /* bitwise neg */ UInt::operator&() /* bitwise and */ UInt::operator&=() UInt::operator|() /* bitwise or */ UInt::operator|=() UInt::operator^() /* bitwise xor */ UInt::operator^=() Big::operator&() Big::operator&=() Big::operator|() Big::operator|=() Big::operator^() Big::operator^=() for Big<> we do not define bitwise neg git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@302 e52654a7-88a9-db11-a3e9-0013d4bc506e --- ttmath/ttmathbig.h | 75 ++++++++++++++++++++++++++++++++++++++++++ ttmath/ttmathint.h | 4 +-- ttmath/ttmathuint.h | 79 ++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 150 insertions(+), 8 deletions(-) diff --git a/ttmath/ttmathbig.h b/ttmath/ttmathbig.h index e58c894..7b4fb4f 100644 --- a/ttmath/ttmathbig.h +++ b/ttmath/ttmathbig.h @@ -938,7 +938,10 @@ public: return CheckCarry(1); if( IsSign() || ss2.IsSign() ) + { + SetNan(); return 2; + } if( IsZero() ) return 0; @@ -998,7 +1001,10 @@ public: return CheckCarry(1); if( IsSign() || ss2.IsSign() ) + { + SetNan(); return 2; + } if( IsZero() ) { @@ -1055,7 +1061,10 @@ public: return CheckCarry(1); if( IsSign() || ss2.IsSign() ) + { + SetNan(); return 2; + } if( ss2.IsZero() ) return 0; @@ -4945,6 +4954,72 @@ public: } + + /*! + * + * bitwise operators + * (we do not define bitwise not) + */ + + + Big operator&(const Big & p2) const + { + Big temp( *this ); + + temp.BitAnd(p2); + + return temp; + } + + + Big & operator&=(const Big & p2) + { + BitAnd(p2); + + return *this; + } + + + Big operator|(const Big & p2) const + { + Big temp( *this ); + + temp.BitOr(p2); + + return temp; + } + + + Big & operator|=(const Big & p2) + { + BitOr(p2); + + return *this; + } + + + Big operator^(const Big & p2) const + { + Big temp( *this ); + + temp.BitXor(p2); + + return temp; + } + + + Big & operator^=(const Big & p2) + { + BitXor(p2); + + return *this; + } + + + + + + /*! this method makes an integer value by skipping any fractions diff --git a/ttmath/ttmathint.h b/ttmath/ttmathint.h index f2de20c..a8af569 100644 --- a/ttmath/ttmathint.h +++ b/ttmath/ttmathint.h @@ -1397,11 +1397,9 @@ public: Int & operator%=(const Int & p2) { - Int temp(*this); Int remainder; - temp.Div(p2, remainder); - + Div(p2, remainder); operator=(remainder); return *this; diff --git a/ttmath/ttmathuint.h b/ttmath/ttmathuint.h index 34f7a20..5041c8b 100644 --- a/ttmath/ttmathuint.h +++ b/ttmath/ttmathuint.h @@ -3259,11 +3259,9 @@ public: UInt & operator%=(const UInt & p2) { - UInt temp(*this); UInt remainder; - temp.Div( p2, remainder ); - + Div( p2, remainder ); operator=(remainder); return *this; @@ -3312,7 +3310,78 @@ public: } - UInt operator>>(int move) + + /*! + * + * bitwise operators + * + */ + + UInt operator~() const + { + UInt temp( *this ); + + temp.BitNot(); + + return temp; + } + + + UInt operator&(const UInt & p2) const + { + UInt temp( *this ); + + temp.BitAnd(p2); + + return temp; + } + + + UInt & operator&=(const UInt & p2) + { + BitAnd(p2); + + return *this; + } + + + UInt operator|(const UInt & p2) const + { + UInt temp( *this ); + + temp.BitOr(p2); + + return temp; + } + + + UInt & operator|=(const UInt & p2) + { + BitOr(p2); + + return *this; + } + + + UInt operator^(const UInt & p2) const + { + UInt temp( *this ); + + temp.BitXor(p2); + + return temp; + } + + + UInt & operator^=(const UInt & p2) + { + BitXor(p2); + + return *this; + } + + + UInt operator>>(int move) const { UInt temp( *this ); @@ -3330,7 +3399,7 @@ public: } - UInt operator<<(int move) + UInt operator<<(int move) const { UInt temp( *this );