Gamma function: Difference between revisions

Added Easylang
(Added Easylang)
(2 intermediate revisions by 2 users not shown)
Line 1,284:
140,0 9,615723196940235E238
170,0 4,269068009004271E304</pre>
 
=={{header|EasyLang}}==
{{trans|AWK}}
<syntaxhighlight>
e = 2.718281828459
func stirling x .
return sqrt (2 * pi / x) * pow (x / e) x
.
print " X Stirling"
for i to 20
d = i / 10
numfmt 2 4
write d & " "
numfmt 3 4
print stirling d
.
</syntaxhighlight>
 
 
=={{header|Elixir}}==
Line 4,415 ⟶ 4,433:
2.0
2.7781584804376647
</pre>
 
=={{header|Rust}}==
====Stirling====
{{trans|AWK}}
 
<syntaxhighlight lang="rust">
use std::f64::consts;
 
fn main() {
let gamma = |x: f64| { assert_ne!(x, 0.0); (2.0*consts::PI/x).sqrt() * (x * (x/consts::E).ln()).exp()};
(1..=20).for_each(|x| {
let x = f64::from(x) / 10.0;
println!("{:.02} => {:.10}", x, gamma(x));
});
}
</syntaxhighlight>
 
{{out}}
<pre>
0.10 => 5.6971871490
0.20 => 3.3259984240
0.30 => 2.3625300363
0.40 => 1.8414763359
0.50 => 1.5203469011
0.60 => 1.3071588574
0.70 => 1.1590532921
0.80 => 1.0533709684
0.90 => 0.9770615079
1.00 => 0.9221370089
1.10 => 0.8834899532
1.20 => 0.8577553354
1.30 => 0.8426782594
1.40 => 0.8367445486
1.50 => 0.8389565525
1.60 => 0.8486932422
1.70 => 0.8656214718
1.80 => 0.8896396353
1.90 => 0.9208427219
2.00 => 0.9595021757
</pre>
 
Line 5,371 ⟶ 5,429:
{{libheader|Wren-math}}
The ''gamma'' method in the Math class is based on the Lanczos approximation.
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
import "./math" for Math
 
var stirling = Fn.new { |x| (2 * Num.pi / x).sqrt * (x / Math.e).pow(x) }
Line 5,379 ⟶ 5,437:
for (i in 1..20) {
var d = i / 10
Fmt.print("$4.2f\t$16.14f\t$16.14f", d, stirling.call(d), Math.gamma(d))
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))")
}</syntaxhighlight>
 
Line 5,390 ⟶ 5,446:
0.10 5.69718714897717 9.51350769866875
0.20 3.32599842402239 4.59084371199881
0.30 2.36253003626962 2.9915689876876099156898768759
0.40 1.84147633593624 2.21815954375769
0.50 1.52034690106628 1.77245385090552
2,083

edits