Skip to content

Instantly share code, notes, and snippets.

@redsquirrel
Forked from jimweirich/gist:189261
Created September 22, 2009 01:23
Show Gist options
  • Save redsquirrel/190711 to your computer and use it in GitHub Desktop.
Save redsquirrel/190711 to your computer and use it in GitHub Desktop.
(define (good-enough? guess x)
(< (abs (- (square guess) x)) 0.001))
;; The good-enough? test used in computing square roots will not be
;; very effective for finding the square roots of very small numbers. Explain.
;;
;; good-enough? is not effective for small numbers because the square
;; of a small number minus the number quickly becomes less than 0.001.
(sqrt 0.00001)
=> .031356
;; correct answer is 0.003162
;; Also, in real computers, arithmetic operations are almost always
;; performed with limited precision. This makes our test inadequate
;; for very large numbers. Explain.
;;
;; good-enough? is not effective for very large numbers because the lack
;; of precision prevents the difference between the two numbers from ever
;; getting small enough.
(sqrt 100000000000000000000000000000000000000000000000000000000000000000)
=> NEVER RETURNS
;; correct answer is 3.16227766016838e+32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment