…一応動いてるような気はするけど…
(define (square x) (* x x)) (define (pi-iter a b c x) (define (good-enough? a b) (< (abs (- a b)) 0.000001)) (if (good-enough? a b) (/ (* (+ a b) (+ a b)) (* 4 c)) (pi-iter (/ (+ a b) 2) (sqrt (* b a)) (- c (* x (square (- (/ (+ a b) 2) a)))) (* 2 x)))) (define pi (pi-iter 1 (/ 1 (sqrt 2)) (/ 1 4) 1))
No comments:
Post a Comment