summaryrefslogtreecommitdiff
path: root/sterling_approx.awk
diff options
context:
space:
mode:
Diffstat (limited to 'sterling_approx.awk')
-rw-r--r--sterling_approx.awk12
1 files changed, 6 insertions, 6 deletions
diff --git a/sterling_approx.awk b/sterling_approx.awk
index cb5f563..4b0741e 100644
--- a/sterling_approx.awk
+++ b/sterling_approx.awk
@@ -1,21 +1,20 @@
#!/usr/bin/awk -f
-
+### sterling_approx.awk
# https://en.wikipedia.org/wiki/Sterling_Approximation
# An alternative approximation for the Gamma function stated by Srinivasa
# Ramanujan (Ramanujan 1988) is
-# Gamma(1+x) ~= sqrt(pi)((x/e)^x)(8x^3 + 4x^2 + x + 1/30)^(1/6)
-# for x >= 0. The equivalent approximation for ln(n!) has an asymptotic error
-# of 1/(1400*n^3) ...
+# Gamma(1+x) ~= sqrt(pi)((x/e)^x)(8x^3 + 4x^2 + x + 1/30)^(1/6)
+# for x >= 0. The equivalent approximation for ln(n!) has an asymptotic
+# error of 1/(1400*n^3) ...
-### sterling_approx.awk
-# https://en.wikipedia.org/wiki/Stirling%27s_approximation
function pwr(x, p) {
return p ? exp(p*log(x)) : 1
}
+
BEGIN {
ARGV[1] ? n = ARGV[1] : n = 0
ARGV[2] ? OFMT = "%." ARGV[2] "g" : OFMT = "%g"
@@ -26,3 +25,4 @@ BEGIN {
}
printf(OFMT ORS, f)
}
+