Fast Fourier transform: Difference between revisions
Content added Content deleted
m (→{{header|VBA}}) |
(→{{header|Raku}}: mark as in need for improvement) |
||
Line 3,645: | Line 3,645: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
{{Works with|rakudo |
{{Works with|rakudo 2022-07}} |
||
{{improve|raku|Not numerically accurate}} |
|||
<syntaxhighlight lang="raku" line>sub fft { |
<syntaxhighlight lang="raku" line>sub fft { |
||
return @_ if @_ == 1; |
return @_ if @_ == 1; |
||
Line 3,653: | Line 3,654: | ||
return flat @evn »+« @odd, @evn »-« @odd; |
return flat @evn »+« @odd, @evn »-« @odd; |
||
} |
} |
||
.say for fft <1 1 1 1 0 0 0 0>;</syntaxhighlight> |
.say for fft <1 1 1 1 0 0 0 0>;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>4+0i |
<pre>4+0i |
||
⚫ | |||
1-2.41421356237309i |
|||
0+0i |
0+0i |
||
1-0.4142135623730949i |
|||
⚫ | |||
0+0i |
0+0i |
||
0.9999999999999999+0.4142135623730949i |
|||
⚫ | |||
0+0i |
0+0i |
||
⚫ | |||
1+2.41421356237309i</pre> |
|||
</pre> |
|||
For the fun of it, here is a purely functional version: |
For the fun of it, here is a purely functional version: |
||
Line 3,673: | Line 3,675: | ||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
<!-- Not really helping now |
|||
This particular version is numerically inaccurate though, because of the pi approximation. It is possible to fix it with the 'cisPi' function available in the TrigPi module: |
This particular version is numerically inaccurate though, because of the pi approximation. It is possible to fix it with the 'cisPi' function available in the TrigPi module: |
||
Line 3,681: | Line 3,684: | ||
fft(@_[1,3...*]) «*« map &cisPi, (0,-2/@_...^-2) |
fft(@_[1,3...*]) «*« map &cisPi, (0,-2/@_...^-2) |
||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
--> |
|||
=={{header|REXX}}== |
=={{header|REXX}}== |