"Also, in real computers, arithmetic operations are almost always performed with limited precision. This makes our test inadequate for very large numbers." Limited precision means that there is a limit to the number of significant figures in our calculations. Suppose the limit is 7 significant figures, x is 10000000000000000000000000000000000000000000000000000 and guess is 100000000000000000001000000. (abs (- (square guess) x)) = 0 and good-enough? returns true, even though guess is off by 1000000.

(define (good-enough? guess old-guess)

(< (abs (- guess old-guess)) (* 0.001 guess)))

(define (sqrt-iter guess x)

(if (good-enough? guess (improve guess x))

(improve guess x)

(sqrt-iter (improve guess x) x)))

## No comments:

Post a Comment