diff --git a/ttmath/ttmathbig.h b/ttmath/ttmathbig.h index 72c59a3..7f3574c 100644 --- a/ttmath/ttmathbig.h +++ b/ttmath/ttmathbig.h @@ -3864,7 +3864,7 @@ public: return false; } - bool AboutEqualWithoutSign(const Big & ss2, int nBitsToIgnore = 4) const + bool AboutEqual(const Big & ss2, int nBitsToIgnore = 4) const { // we should check the mantissas beforehand because sometimes we can have // a mantissa set to zero but in the exponent something another value @@ -3874,12 +3874,30 @@ public: return true; } + if( IsSign() != ss2.IsSign() ) + { + return false; + } + if( exponent==ss2.exponent ) { if (mantissa == ss2.mantissa) { return(true); } + if( IsSign() != ss2.IsSign() ) + { + // we need to check the difference (both might be around Zero) + Big temp(*this); + + temp.Sub(ss2); + + Int exponent_diff(exponent - temp.exponent); + + return(exponent_diff > man*TTMATH_BITS_PER_UINT-nBitsToIgnore); + } + + // faster to mask the bits! ASSERT(nBitsToIgnore < TTMATH_BITS_PER_UINT); for (int n = man-1; n > 0; --n)