Gamma function: Difference between revisions
Content deleted Content added
m Phix/mpfr |
Added Wren |
||
Line 4,255:
1.9 0.961765831907391
2.0 1.000000000000000
</pre>
=={{header|Wren}}==
{{trans|Kotlin}}
{{libheader|Wren-fmt}}
{{libheader|Wren-math}}
The ''gamma'' method in the Math class is based on the Lanczos approximation.
<lang ecmascript>import "/fmt" for Fmt
import "/math" for Math
var stirling = Fn.new { |x| (2 * Num.pi / x).sqrt * (x / Math.e).pow(x) }
System.print(" x\tStirling\t\tLanczos\n")
for (i in 1..20) {
var d = i / 10
System.write("%(Fmt.f(4, d, 2))\t")
System.write("%(Fmt.f(16, stirling.call(d), 14))\t")
System.print("%(Fmt.f(16, Math.gamma(d), 14))")
}</lang>
{{out}}
<pre>
x Stirling Lanczos
0.10 5.69718714897717 9.51350769866875
0.20 3.32599842402239 4.59084371199881
0.30 2.36253003626962 2.99156898768760
0.40 1.84147633593624 2.21815954375769
0.50 1.52034690106628 1.77245385090552
0.60 1.30715885744836 1.48919224881282
0.70 1.15905329211392 1.29805533264756
0.80 1.05337096842561 1.16422971372530
0.90 0.97706150787770 1.06862870211932
1.00 0.92213700889579 1.00000000000000
1.10 0.88348995316870 0.95135076986687
1.20 0.85775533539659 0.91816874239976
1.30 0.84267825944839 0.89747069630628
1.40 0.83674454863708 0.88726381750308
1.50 0.83895655252650 0.88622692545276
1.60 0.84869324215257 0.89351534928769
1.70 0.86562147179388 0.90863873285329
1.80 0.88963963528799 0.93138377098024
1.90 0.92084272189423 0.96176583190739
2.00 0.95950217574449 1.00000000000000
</pre>
|