File: pi.l

package info (click to toggle)
picolisp 3.1.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,100 kB
  • sloc: ansic: 14,205; lisp: 795; makefile: 290; sh: 13
file content (23 lines) | stat: -rw-r--r-- 522 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 16jun11abu
# (c) Software Lab. Alexander Burger

##############################
# Iterative calculation of PI:
#  S = 0
#  P = 2
#  Loop
#     S = sqrt(S+2)
#     P = 2*P/S
##############################

(de pi (N Eps)
   (default N *Scl  Eps 100)
   (let (Scl (** 10 N)  S 0  N2 (* 2 Scl)  P N2  P2 0)
      (while (> (- P P2) Eps)
         (setq
            P2 P
            S (sqrt (* Scl (+ S N2)))
            P (*/ N2 P S) ) ) ) )

(test 3141592653589793238462643383279502884197169399375105820975043
   (pi 60) )