added: UInt::Sqrt() - a new algorithm for calculating the square root
git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@228 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
2feabc64e2
commit
e73ce2f8bc
|
@ -44,6 +44,7 @@ Version 0.9.0 prerelease (2009.11.01):
|
||||||
uint FromString(const wchar_t * source, const Conv & conv, const wchar_t **, bool *)
|
uint FromString(const wchar_t * source, const Conv & conv, const wchar_t **, bool *)
|
||||||
uint FromString(const std::string & string, const Conv & conv, const wchar_t **, bool *)
|
uint FromString(const std::string & string, const Conv & conv, const wchar_t **, bool *)
|
||||||
uint FromString(const std::wstring & string, const Conv & conv, const wchar_t **, bool *)
|
uint FromString(const std::wstring & string, const Conv & conv, const wchar_t **, bool *)
|
||||||
|
* added: UInt::Sqrt() - a new algorithm for calculating the square root
|
||||||
* changed: Factorial() is using the Gamma() function now
|
* changed: Factorial() is using the Gamma() function now
|
||||||
* changed: Big::Div(ss2)
|
* changed: Big::Div(ss2)
|
||||||
Big::Mod(ss2)
|
Big::Mod(ss2)
|
||||||
|
|
|
@ -1509,6 +1509,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
#ifdef TTMATH_CONSTANTSGENERATOR
|
#ifdef TTMATH_CONSTANTSGENERATOR
|
||||||
|
|
|
@ -534,6 +534,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
*
|
*
|
||||||
* convertion methods
|
* convertion methods
|
||||||
|
|
|
@ -2252,6 +2252,50 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
square root
|
||||||
|
e.g. Sqrt(9) = 3
|
||||||
|
('digit-by-digit' algorithm)
|
||||||
|
*/
|
||||||
|
void Sqrt()
|
||||||
|
{
|
||||||
|
UInt<value_size> bit, temp;
|
||||||
|
|
||||||
|
if( IsZero() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
UInt<value_size> value(*this);
|
||||||
|
|
||||||
|
SetZero();
|
||||||
|
bit.SetZero();
|
||||||
|
bit.table[value_size-1] = (TTMATH_UINT_HIGHEST_BIT >> 1);
|
||||||
|
|
||||||
|
while( bit > value )
|
||||||
|
bit.Rcr(2);
|
||||||
|
|
||||||
|
while( !bit.IsZero() )
|
||||||
|
{
|
||||||
|
temp = *this;
|
||||||
|
temp.Add(bit);
|
||||||
|
|
||||||
|
if( value >= temp )
|
||||||
|
{
|
||||||
|
value.Sub(temp);
|
||||||
|
Rcr(1);
|
||||||
|
Add(bit);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Rcr(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bit.Rcr(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TTMATH_LOG("UInt::Sqrt")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
this method sets n first bits to value zero
|
this method sets n first bits to value zero
|
||||||
|
|
Loading…
Reference in New Issue