콘텐츠로 건너뛰기

SICP)연습문제 1.7

  • 기준

Exercise 1.7. The good-enough? test used in computing square roots will not be very
effective for finding the square roots of very small numbers. Also, in real computers,
arithmetic operations are almost always performed with limited precision. This makes our
test inadequate for very large numbers. Explain these statements, with examples showing
how the test fails for small and large numbers. An alternative strategy for implementing
good-enough? is to watch how guess changes from one iteration to the next and to
stop when the change is a very small fraction of the guess. Design a square-root procedure
that uses this kind of end test. Does this work better for small and large numbers?

A)

해당 함수는 근사값만을 구하기 때문에 4.0 이나 16.0 과 같은 정수로 떨어지는 값을 넣어보면 정확한 값이 나오지 않는다는 것을 쉽게 알 수 있다. good-enough 에서 정밀도를 높이면 더 근사한 값이 나오지만 속도가 무척 느려진다.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다