2014-10-29 30 views
1

版本信息計算奇怪的輸出:版本4.9.0.1(穩定性/ 4.9.0)(REV 8b3189b)MACOSX-UNIX的鐺,X86-64用PI雞方案

的代碼實際上是鍛鍊1.3 .1 SICP:

(define (product term a next b) 
    (define (iter a result) 
     (if (> a b) 
      result 
      (iter (next a) (* (term a) result)) 
     ) 
    ) 
    (iter a 1) 
) 

(define (get-pi n) 
    (define (next x) (+ x 2)) 
    (define (term x) (* x x)) 
    (* 8 n (/ (product term 4 next n) (product term 3 next (+ n 1)))) 
) 

輸出:

#;102> (get-pi 165) 
3.13208714360219 
#;103> (get-pi 167) 
3.13220081034665 
#;104> (get-pi 169) 
3.13231179078142 
#;105> (get-pi 170) 
0.0 

爲什麼結果變成了0.0≦

謝謝!

回答

3

雞在默認情況下不會實現完整的數字塔。您需要(use numbers)

我沒有安裝Chicken,但您可能必須使用(exact->inexact (get-pi 170))才能獲得與以前相同的結果。