2014-02-06 2 views
0

그래서 BigInteger를의 제곱근을 찾기 위해 뉴턴 - 랩슨 방법을 사용하려고 시도하고있다. - 그것은 소수 장소를 필요로 즉C#에서의 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 루프에서 엡실론의 정확성의 정도 내에 충분히 정확하지 것 같다 :

여기 내 코드입니다. 내 질문은 어떻게/어떻게/어디에 두 번 루프를 결국 false를 반환하게 변환합니까?

+1

ummm 'BigInteger'는 부동 소수점 연산이 아닌 정수를위한 것입니다. –

+0

가능한 중복 [BigInteger (System.Numerics.BigInteger)의 제곱근 계산] (http://stackoverflow.com/questions/3432412/calculate-square-root-of-a-biginteger-system-numerics-biginteger) – AlexH

+0

그렇다면 매우 큰 숫자로 어떻게 부동 소수점 연산을 수행 할 수 있습니까? 당신은'사용할 수 있습니다 더 정확성을 – Gerald

답변

1

잘못된 데이터 형식을 사용하고 있습니다. 소수점을 사용하려면 double, float, decimal 또는 Complex을 사용해야합니다.

이러한 모든 유형의 링크를 확인하면 정확한 자릿수를 볼 수 있습니다.