mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:17:35 +00:00
AK+Everywhere: Add sincos and use it in some places
Calculating sin and cos at once is quite a bit cheaper than calculating them individually. x87 has even a dedicated instruction for it: `fsincos`.
This commit is contained in:
parent
47fe911196
commit
cd21e03225
6 changed files with 30 additions and 10 deletions
|
@ -28,11 +28,12 @@ constexpr void fft(Span<Complex<double>> sample_data, bool invert = false)
|
|||
|
||||
for (int len = 2; len <= n; len <<= 1) {
|
||||
double ang = 2 * AK::Pi<double> / len * (invert ? -1 : 1);
|
||||
Complex<double> wlen(AK::cos(ang), AK::sin(ang));
|
||||
Complex<double> wlen = Complex<double>::from_polar(1., ang);
|
||||
for (int i = 0; i < n; i += len) {
|
||||
Complex<double> w = { 1., 0. };
|
||||
for (int j = 0; j < len / 2; j++) {
|
||||
Complex<double> u = sample_data[i + j], v = sample_data[i + j + len / 2] * w;
|
||||
Complex<double> u = sample_data[i + j];
|
||||
Complex<double> v = sample_data[i + j + len / 2] * w;
|
||||
sample_data[i + j] = u + v;
|
||||
sample_data[i + j + len / 2] = u - v;
|
||||
w *= wlen;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue