Thiele's interpolation formula: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: sort hash keys as order is no longer stable) |
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: added 'Promise' for concurrency) |
||
Line 806: | Line 806: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
{{Works with|rakudo|2018. |
{{Works with|rakudo|2018.09}}<br> |
||
Implemented to parallel the |
Implemented to parallel the generalized formula, making for clearer, but slower, code. Offsetting that, the use of <code>Promise</code> allows concurrent calculations, so running all three types of interpolation should not take any longer than running just one (presuming available cores). |
||
<lang perl6># reciprocal difference: |
<lang perl6># reciprocal difference: |
||
multi sub ρ(&f, @x where * < 1) { 0 } # Identity |
multi sub ρ(&f, @x where * < 1) { 0 } # Identity |
||
Line 842: | Line 843: | ||
sub MAIN($tblsz = 12) { |
sub MAIN($tblsz = 12) { |
||
my %invsin = mk-inv(&sin, 0.05, $tblsz); |
|||
my |
my ($sin_pi, $cos_pi, $tan_pi); |
||
my % |
my $p1 = Promise.start( { my %invsin = mk-inv(&sin, 0.05, $tblsz); $sin_pi = 6 * thiele(0.5, %invsin, 0) } ); |
||
my $p2 = Promise.start( { my %invcos = mk-inv(&cos, 0.05, $tblsz); $cos_pi = 3 * thiele(0.5, %invcos, 0) } ); |
|||
my $ |
my $p3 = Promise.start( { my %invtan = mk-inv(&tan, 0.05, $tblsz); $tan_pi = 4 * thiele(1.0, %invtan, 0) } ); |
||
await $p1, $p2, $p3; |
|||
my $cos_pi = 3 * thiele(0.5, %invcos, 0); |
|||
my $tan_pi = 4 * thiele(1.0, %invtan, 0); |
|||
say "pi = {pi}"; |
say "pi = {pi}"; |