所以我试图使用Newton-Raphson方法找到BigInteger的平方根。
这是我的代码:
private void sqrRt(BigInteger candidate)
{
BigInteger epsilon = new BigInteger(0.0001);
BigInteger guess = candidate / 2;
while (BigInteger.Abs(guess * guess - candidate) >= epsilon)
{
// guess = guess - (((guess**2) - y)/(2*guess))
guess = BigInteger.Subtract(guess, BigInteger.Divide(BigInteger.Subtract(BigInteger.Multiply(guess, guess), candidate), BigInteger.Multiply(2, guess)));
MessageBox.Show(Convert.ToString(guess));
}
}
问题似乎是BigInteger不够精确到在while循环中的epsilon精度范围内 - 即它需要一个小数位。我的问题是什么/如何/在哪里转换为double以使while循环最终返回false?