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:
parent
e73ce2f8bc
commit
cccf82797f
|
@ -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;
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
Loading…
Reference in New Issue