From 51b2c974a16050b9b13f77876e1f51d1675fd818 Mon Sep 17 00:00:00 2001 From: Christian Kaiser Date: Fri, 26 Jun 2009 15:24:27 +0000 Subject: [PATCH] - changed "AboutEqualWithoutSign()" to "AboutEqual()" because we need to take the sign into account! git-svn-id: svn://ttmath.org/publicrep/ttmath/branches/chk@173 e52654a7-88a9-db11-a3e9-0013d4bc506e --- ttmath/ttmathbig.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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)