Thiele's interpolation formula: Difference between revisions
m
→{{header|Perl 6}}: sort hash keys as order is no longer stable
(→{{header|Haskell}}: 100 -> 1000 (+ updated outputs)) |
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: sort hash keys as order is no longer stable) |
||
Line 806:
=={{header|Perl 6}}==
{{Works with|rakudo|
Implemented to parallel the (generalized) formula. (i.e. clearer, but naive and very slow.)
<lang perl6>
multi sub ρ(&f, @x where * < 1) { 0 } # Identity
multi sub ρ(&f, @x where * == 1) { &f(@x[0]) }
Line 825 ⟶ 823:
my &f = {%f{$^a}}; # f(x) as a table lookup
# must sort hash keys to maintain order between invocations
my $a = ρ(&f, %f.keys.sort[^($ord +1)]);
my $b = ρ(&f, %f.keys.sort[^($ord -1)]);
my $num = $x - %f.keys.sort[$ord];
my $cont = thiele($x, %f, $ord +1);
|