picolisp

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/picolisp.git/
Log | Files | Refs | README | LICENSE

pi.l (522B)


      1 # 16jun11abu
      2 # (c) Software Lab. Alexander Burger
      3 
      4 ##############################
      5 # Iterative calculation of PI:
      6 #  S = 0
      7 #  P = 2
      8 #  Loop
      9 #     S = sqrt(S+2)
     10 #     P = 2*P/S
     11 ##############################
     12 
     13 (de pi (N Eps)
     14    (default N *Scl  Eps 100)
     15    (let (Scl (** 10 N)  S 0  N2 (* 2 Scl)  P N2  P2 0)
     16       (while (> (- P P2) Eps)
     17          (setq
     18             P2 P
     19             S (sqrt (* Scl (+ S N2)))
     20             P (*/ N2 P S) ) ) ) )
     21 
     22 (test 3141592653589793238462643383279502884197169399375105820975043
     23    (pi 60) )