]> gitweb.factorcode.org Git - factor.git/commitdiff
Stirling's factorial approximation
authorAlexander Solovyov <piranha@piranha.org.ua>
Tue, 12 Feb 2008 22:24:32 +0000 (00:24 +0200)
committerAlexander Solovyov <piranha@piranha.org.ua>
Tue, 12 Feb 2008 22:24:32 +0000 (00:24 +0200)
extra/math/analysis/analysis.factor

index bde5cad7a019015d2bc2fde67ef8ec29d5838c5d..2973d3d3f2fb6572cebdb084d0af724e79b3927b 100644 (file)
@@ -108,3 +108,12 @@ PRIVATE>
         swap -1.0 * exp
         *
     ] if ;
+
+! James Stirling's approximation for N!:
+! http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Numerical/Stirling/
+
+: stirling-fact ( n -- fact )
+  [ pi 2 * * sqrt ]
+  [ dup e / swap ^ ]
+  [ 12 * recip 1 + ]
+  tri * * ;