summaryrefslogtreecommitdiff
path: root/sterling_approx.awk
diff options
context:
space:
mode:
authorwukong <wukong@longaeva>2026-04-10 23:46:12 -0700
committerwukong <wukong@longaeva>2026-04-10 23:46:12 -0700
commit4c4eb1bd8f003b3b57707badd2dd089ed193a896 (patch)
tree15b62907fffd70c46a9b4369df93ab33c6aa88ac /sterling_approx.awk
parente7d1781578e846a7b1d634cd43c8fab00a67b883 (diff)
renamed fir window generators;
minor edits to whitespace and comments for more consistent style;
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)
}
+