merged: AboutEqual() from chk branch
deleted: properties svn:mime-type from ttmath.h (it was for testing viewvc) git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@186 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
3544a1df3c
commit
0d71b0cec2
|
@ -1,4 +1,4 @@
|
|||
Version 0.9.0 prerelease (2009.08.04):
|
||||
Version 0.9.0 prerelease (2009.09.05):
|
||||
* added: support for wide characters (wchar_t)
|
||||
wide characters are used when macro TTMATH_USE_WCHAR is defined
|
||||
this macro is defined automatically when there is macro UNICODE or _UNICODE defined
|
||||
|
@ -20,6 +20,8 @@ Version 0.9.0 prerelease (2009.08.04):
|
|||
* added: multithread support for Big<> class
|
||||
you should compile with TTMATH_MULTITHREADS
|
||||
and use TTMATH_MULTITHREADS_HELPER macro somewhere in your *.cpp file
|
||||
* added: Big::AboutEqual(const Big<exp,man> & ss2, int nBitsToIgnore = 4)
|
||||
the last nBitsToIgnore bits from mantissas will be skipped when comparing
|
||||
* changed: Factorial() is using the Gamma() function now
|
||||
* removed: Parser<>::SetFactorialMax() method
|
||||
the factorial() is such a fast now that we don't need the method longer
|
||||
|
|
|
@ -3916,6 +3916,77 @@ public:
|
|||
}
|
||||
|
||||
|
||||
bool AboutEqual(const Big<exp,man> & 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
|
||||
// (maybe we've forgotten about calling CorrectZero() ?)
|
||||
if( mantissa.IsZero() )
|
||||
{
|
||||
if( ss2.mantissa.IsZero() )
|
||||
return true;
|
||||
|
||||
return(ss2.AboutEqual(*this,nBitsToIgnore));
|
||||
}
|
||||
|
||||
if( ss2.mantissa.IsZero() )
|
||||
{
|
||||
return(this->exponent <= uint(2*(-sint(man*TTMATH_BITS_PER_UINT))+nBitsToIgnore));
|
||||
}
|
||||
|
||||
// exponents may not differ much!
|
||||
ttmath::Int<exp> expdiff(this->exponent - ss2.exponent);
|
||||
|
||||
// they may differ one if for example mantissa1=0x80000000, mantissa2=0xffffffff
|
||||
if( ttmath::Abs(expdiff) > 1 )
|
||||
return(false);
|
||||
|
||||
// calculate the 'difference' mantissa
|
||||
ttmath::UInt<man> man1(this->mantissa);
|
||||
ttmath::UInt<man> man2(ss2.mantissa);
|
||||
ttmath::UInt<man> mandiff;
|
||||
|
||||
switch( expdiff.ToInt() )
|
||||
{
|
||||
case +1:
|
||||
man2.Rcr(1,0);
|
||||
mandiff = man1;
|
||||
mandiff.Sub(man2);
|
||||
break;
|
||||
case -1:
|
||||
man1.Rcr(1,0);
|
||||
mandiff = man2;
|
||||
mandiff.Sub(man1);
|
||||
break;
|
||||
default:
|
||||
if( man2 > man1 )
|
||||
{
|
||||
mandiff = man2;
|
||||
mandiff.Sub(man1);
|
||||
}
|
||||
else
|
||||
{
|
||||
mandiff = man1;
|
||||
mandiff.Sub(man2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// faster to mask the bits!
|
||||
TTMATH_ASSERT( nBitsToIgnore < TTMATH_BITS_PER_UINT );
|
||||
|
||||
for( int n = man-1; n > 0; --n )
|
||||
{
|
||||
if( mandiff.table[n] != 0 )
|
||||
return(false);
|
||||
}
|
||||
|
||||
uint nMask = ~((1 << nBitsToIgnore) - 1);
|
||||
|
||||
return((mandiff.table[0] & nMask) == 0);
|
||||
}
|
||||
|
||||
|
||||
bool operator<(const Big<exp,man> & ss2) const
|
||||
{
|
||||
if( IsSign() && !ss2.IsSign() )
|
||||
|
|
Loading…
Reference in New Issue