(Def (PiCalc) //////////////////////////////////////////////////////////////// // Approximation to _Pi based on Algorithm 2.2 // page 48 of Borwein and Borwein, Pi and the AGM. //////////////////////////////////////////////////////////////// (Local p a1 b1 c1 a2 b2 c2 k old new answer) (WithMorePrecision 20 (Setq a1 1.0) (Setq b1 (Sqrt 0.5)) (Setq c1 b1) (Setq old 0.5) (Setq k 0) (While TRUE (Setq a2 (/ (+ a1 b1) 2)) (Setq b2 (Sqrt (* a1 b1))) (Setq c2 (/ (^ c1 2) (* 4 a2))) (PrintLine (/ (* 2 (^ a2 2)) (- 1 old))) (Setq k (+ k 1)) (Setq a1 a2) (Setq b1 b2) (Setq c1 c2) (Setq new (+ old (* (^ 2 k) (^ c1 2)))) (If (= new old) (Break)) (Setq old new)) (Setq answer (/ (* 2 (^ a2 2)) (- 1 old)))) (Setq answer (Float answer)) (Return answer) )