removed: Big::AboutEqualWithoutSign()
it was broken (it lacks the case when either 'this' or 'ss2' is zero) git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@206 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
e765fba8a1
commit
32ebbbfd9e
|
@ -4155,139 +4155,6 @@ public:
|
|||
}
|
||||
|
||||
|
||||
/*!
|
||||
this method compares this and ss2 by ingoring some nBitsToIgnore last bits from mantissas
|
||||
if nBitsToIgnore is 0 then the method is equivalent to EqualWithoutSign() method
|
||||
(signs are not checked, we don't check the NaN flag too)
|
||||
|
||||
sample:
|
||||
Big<1,1> a, b;
|
||||
a = " 1234.5678";
|
||||
b = "-1234.5677999";
|
||||
// binary a: 10011010010.100100010101101101010
|
||||
// binary b: -10011010010.100100010101101101000
|
||||
// two last bits are different
|
||||
if( a.AboutEqualWithoutSign(b, 2) ) // the result is true
|
||||
std::cout << "true" << std::endl;
|
||||
|
||||
|
||||
***warning broken*** doesn't work if 'this' or 'ss2' is zero
|
||||
|
||||
|
||||
*/
|
||||
bool AboutEqualWithoutSign(const Big<exp,man> & ss2, uint ignore_bits = 4) const
|
||||
{
|
||||
TTMATH_ASSERT( ignore_bits < man*TTMATH_BITS_PER_UINT )
|
||||
|
||||
if( IsZero() && ss2.IsZero() )
|
||||
return true;
|
||||
|
||||
if( exponent == ss2.exponent )
|
||||
return AboutEqualExpEqual(mantissa, ss2.mantissa, ignore_bits);
|
||||
|
||||
|
||||
UInt<exp> exp_diff;
|
||||
exp_diff = exponent;
|
||||
exp_diff.Sub(ss2.exponent);
|
||||
|
||||
if( exp_diff == 1 )
|
||||
{
|
||||
// exponent is > ss2.exponent
|
||||
UInt<man> man_diff(mantissa);
|
||||
UInt<man> man_temp(ss2.mantissa);
|
||||
man_temp.Rcr(1, 0);
|
||||
man_diff.Sub(man_temp);
|
||||
|
||||
return AboutEqualZero(man_diff, ignore_bits);
|
||||
}
|
||||
else
|
||||
if( exp_diff == -1 )
|
||||
{
|
||||
// exponent is < ss2.exponent
|
||||
UInt<man> man_diff(ss2.mantissa);
|
||||
UInt<man> man_temp(mantissa);
|
||||
man_temp.Rcr(1, 0);
|
||||
man_diff.Sub(man_temp);
|
||||
|
||||
return AboutEqualZero(man_diff, ignore_bits);
|
||||
}
|
||||
|
||||
// exp_diff is different from zero, one or minus one
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
/*!
|
||||
an auxiliary method for calculating AboutEqualWithoutSign()
|
||||
we're using it when exponent is equal ss2.exponent
|
||||
*/
|
||||
bool AboutEqualExpEqual(const UInt<man> & man1, const UInt<man> & man2, uint ignore_bits) const
|
||||
{
|
||||
uint words = ignore_bits / TTMATH_BITS_PER_UINT;
|
||||
uint bits = ignore_bits % TTMATH_BITS_PER_UINT;
|
||||
uint i;
|
||||
|
||||
if( bits == 0 )
|
||||
{
|
||||
i = words;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = words + 1;
|
||||
uint mask = TTMATH_UINT_MAX_VALUE << bits;
|
||||
|
||||
if( (man1.table[words] & mask) != (man2.table[words] & mask) )
|
||||
return false;
|
||||
}
|
||||
|
||||
for( ; i<man ; ++i )
|
||||
{
|
||||
if( man1.table[i] != man2.table[i] )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
an auxiliary method for calculating AboutEqualWithoutSign()
|
||||
*/
|
||||
bool AboutEqualZero(const UInt<man> & man_diff, uint ignore_bits) const
|
||||
{
|
||||
uint words = ignore_bits / TTMATH_BITS_PER_UINT;
|
||||
uint bits = ignore_bits % TTMATH_BITS_PER_UINT;
|
||||
uint i;
|
||||
|
||||
if( bits == 0 )
|
||||
{
|
||||
i = words;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = words + 1;
|
||||
uint mask = TTMATH_UINT_MAX_VALUE << bits;
|
||||
|
||||
if( (man_diff.table[words] & mask) != 0 )
|
||||
return false;
|
||||
}
|
||||
|
||||
for( ; i<man ; ++i )
|
||||
{
|
||||
if( man_diff.table[i] != 0 )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
bool operator<(const Big<exp,man> & ss2) const
|
||||
{
|
||||
if( IsSign() && !ss2.IsSign() )
|
||||
|
|
Loading…
Reference in New Issue