Gamma function: Difference between revisions

Added XPL0 example.
(→‎{{header|R}}: Issue found in previous R implementation step using 'seq.int' function: imaginary parts discarded in coercion; The edit resolved the issue and retain the imaginary part to make sure the precision. The edited lanczos(z) was benchmarked with gammaz(z) and complex_gamma(z) from 'pracma' and 'hypergeo' libraries to cross validate the solution accuracy)
(Added XPL0 example.)
Line 5,272:
1.90 0.92084272189423 0.96176583190739
2.00 0.95950217574449 1.00000000000000
</pre>
 
=={{header|XPL0}}==
{{trans|Ada}}
<syntaxhighlight lang "XPL0">function real Gamma (X);
real X, A, Y, Sum;
integer N;
begin
A \constant array (0..29) of Long_Float\ :=
[ 1.00000_00000_00000_00000,
0.57721_56649_01532_86061,
-0.65587_80715_20253_88108,
-0.04200_26350_34095_23553,
0.16653_86113_82291_48950,
-0.04219_77345_55544_33675,
-0.00962_19715_27876_97356,
0.00721_89432_46663_09954,
-0.00116_51675_91859_06511,
-0.00021_52416_74114_95097,
0.00012_80502_82388_11619,
-0.00002_01348_54780_78824,
-0.00000_12504_93482_14267,
0.00000_11330_27231_98170,
-0.00000_02056_33841_69776,
0.00000_00061_16095_10448,
0.00000_00050_02007_64447,
-0.00000_00011_81274_57049,
0.00000_00001_04342_67117,
0.00000_00000_07782_26344,
-0.00000_00000_03696_80562,
0.00000_00000_00510_03703,
-0.00000_00000_00020_58326,
-0.00000_00000_00005_34812,
0.00000_00000_00001_22678,
-0.00000_00000_00000_11813,
0.00000_00000_00000_00119,
0.00000_00000_00000_00141,
-0.00000_00000_00000_00023,
0.00000_00000_00000_00002
];
Y := X - 1.0;
Sum := A (29);
for N:= 29-1 downto 0 do
Sum := Sum * Y + A (N);
return 1.0 / Sum;
end \Gamma\;
 
\Test program:
integer I;
begin
Format(0, 14);
for I:= 1 to 10 do
[RlOut(0, Gamma (Float (I) / 3.0)); CrLf(0)];
end</syntaxhighlight>
{{out}}
<pre>
2.67893853470775E+000
1.35411793942640E+000
1.00000000000000E+000
8.92979511569249E-001
9.02745292950934E-001
1.00000000000000E+000
1.19063934875900E+000
1.50457548825154E+000
1.99999999999397E+000
2.77815847933857E+000
</pre>
 
298

edits