some solutions for MIT Press's "structure and interpretation of computer programs", I guess
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
480 B

(define (average x y)
(/ (+ x y) 2))
(define (improve guess x)
(average guess (/ x guess)))
(define (good-enough? guess old)
(< (abs (- guess old)) 0.001))
(define (sqrt-iter guess old x)
(if (good-enough? guess old)
(sqrt-iter (improve guess x) guess x)))
(define (my-sqrt x)
(sqrt-iter 1.0 x x))
;; floating point inaccuracies are the big player here
(display (my-sqrt 10000000000000))
(display " ")
(display (my-sqrt 0.0000003))