Gamma function: Difference between revisions

add lambdatalk code
(add lambdatalk code)
Line 2,341:
2.00 0.959502175744492 1.000000000000000
</pre>
 
=={{header|Lambdatalk}}==
Following Javascript, with Lanczos approximation.
 
<syntaxhighlight lang="Scheme">
 
{def gamma.p
{A.new 0.99999999999980993
676.5203681218851
-1259.1392167224028
771.32342877765313
-176.61502916214059
12.507343278686905
-0.13857109526572012
9.9843695780195716e-6
1.5056327351493116e-7
}}
-> gamma.p
 
{def gamma.rec
{lambda {:x :a :i}
{if {< :i {A.length {gamma.p}}}
then {gamma.rec :x
{+ :a {/ {A.get :i {gamma.p}} {+ :x :i}} }
{+ :i 1}}
else :a
}}}
-> gamma.rec
 
{def gamma
{lambda {:x}
{if {< :x 0.5}
then {/ {PI}
{* {sin {* {PI} :x}}
{gamma {- 1 :x}}}}
else {let { {:x {- :x 1}}
{:t {+ {- :x 1} 7 0.5}}
} {* {sqrt {* 2 {PI}}}
{pow :t {+ :x 0.5}}
{exp -:t}
{gamma.rec :x {A.first {gamma.p}} 1}}
}}}}
-> gamma
 
{S.map {lambda {:i}
{div} Γ(:i) = {gamma :i}}
{S.serie -5.5 5.5 0.5}}
 
Γ(-5.5) = 0.010912654781909836
Γ(-5) = -42755084646679.17
Γ(-4.5) = -0.06001960130050417
Γ(-4) = 267219279041745.34
Γ(-3.5) = 0.27008820585226917
Γ(-3) = -1425169488222640
Γ(-2.5) = -0.9453087204829418
Γ(-2) = 6413262697001885
Γ(-1.5) = 2.363271801207352
Γ(-1) = -25653050788007544
Γ(-0.5) = -3.5449077018110295
Γ(0) = Infinity
Γ(0.5) = 1.7724538509055159
Γ(1) = 0.9999999999999998
Γ(1.5) = 0.8862269254527586
Γ(2) = 1.0000000000000002
Γ(2.5) = 1.3293403881791384
Γ(3) = 2.000000000000001
Γ(3.5) = 3.3233509704478426
Γ(4) = 6.000000000000007
Γ(4.5) = 11.631728396567446
Γ(5) = 23.999999999999996
Γ(5.5) = 52.34277778455358
</syntaxhighlight>
 
=={{header|Limbo}}==
99

edits