المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Getting Square Root of BigInteger



C# Programming
10-24-2012, 03:52 AM
Hi
I found here in an article, a ready function which returns the square root of biginteger, but I can't understand how it works. Can someone please explain me the algorithm and why it works:

public static BigInteger IntegerSqrt(BigInteger n)
{

BigInteger oldValue = new BigInteger(0);
BigInteger newValue;
newValue=n;

while (BigInteger.Abs(newValue - oldValue) >=1)
{
oldValue = newValue;
newValue = (oldValue + (n / oldValue)) /2;
}

return newValue;
}

thanks