Anonymous user
Fast Fourier transform: Difference between revisions
Updated D code
(Added BBC BASIC) |
(Updated D code) |
||
Line 344:
<lang d>import std.stdio, std.math, std.algorithm, std.range;
/*auto*/ creal[] fft(/*in*/ creal[] x) /*pure nothrow*/ {
int N = x.length;
if (N <= 1) return x;
auto ev = fft(array(stride(x, 2)));
auto od = fft(array(stride(x[1 .. $], 2)));
auto l = map!
auto r = map!
return array(chain(l, r));
}
void main() {
writeln(fft([1.0L+0i, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0]));
}</lang>
Output:<pre>[4+0i, 1+-2.41421i, 0+0i, 1+-0.414214i, 0+0i, 1+0.414214i, 0+0i, 1+2.41421i]</pre>
|