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))
m (→‎{{header|Perl 6}}: sort hash keys as order is no longer stable)
Line 806:
 
=={{header|Perl 6}}==
{{Works with|rakudo|20162018.0705}}<br>
Implemented to parallel the (generalized) formula. (i.e. clearer, but naive and very slow.)
<lang perl6>use# v6;reciprocal difference:
# reciprocal difference:
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
# Caveat: depends on the fact that Rakudo maintains key order within hashes
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);
2,392

edits