]> gitweb.factorcode.org Git - factor.git/blob - extra/benchmark/find-pi/find-pi.factor
factor: trim using lists
[factor.git] / extra / benchmark / find-pi / find-pi.factor
1 ! Copyright (C) 2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math ;
4 IN: benchmark.find-pi
5
6 :: find-pi-to ( accuracy -- n approx )
7     1 4 [
8         over [ 2 * 1 + ] [ odd? [ neg ] when ] bi
9         4 swap / [ + ] keep
10         abs accuracy >= [ 1 + ] 2dip
11     ] loop ;
12
13 : find-pi-benchmark ( -- )
14     0.0005 find-pi-to drop 4001 assert= ;
15
16 MAIN: find-pi-benchmark