added: Big::Sqrt()

global algorithm ttmath::Sqrt() moved to Big::Sqrt()


git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@229 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2009-11-01 13:41:29 +00:00
parent e73ce2f8bc
commit cccf82797f
2 changed files with 28 additions and 14 deletions

View File

@ -1843,20 +1843,7 @@ namespace ttmath
return ValueType(); // NaN is set by default
}
if( x.IsZero() )
{
// Sqrt(0) = 0
if( err )
*err = err_ok;
return x;
}
ValueType pow;
pow.Set05();
// PowFrac can return only a carry because x is greater than zero
uint c = x.PowFrac(pow);
uint c = x.Sqrt();
if( err )
*err = c ? err_overflow : err_ok;

View File

@ -1509,6 +1509,33 @@ public:
}
/*!
this function calculates the square root
Sqrt(9) = 3
return: 0 - ok
1 - carry
2 - improper argument (this<0 or NaN)
*/
uint Sqrt()
{
if( IsNan() || IsSign() )
{
SetNan();
return 2;
}
if( IsZero() )
return 0;
Big<exp, man> pow;
pow.Set05();
// PowFrac can return only a carry because x is greater than zero
return PowFrac(pow);
}
private: