-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathexpj.hpp
39 lines (30 loc) · 819 Bytes
/
expj.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
#include <array>
#include <cmath>
#include <complex>
#include "utils.hpp"
namespace kvak {
template <int N, typename Float = float>
class expj_precalc {
public:
expj_precalc()
{
for (unsigned int i = 0; i < N; i++) {
Float angle = static_cast<Float>(i) / (N - 1) * 2*M_PI;
this->values[i] = utils::expj(angle);
}
}
std::complex<Float> operator()(Float angle) const
{
// Observation: symmetry between the quarter-circles could be exploited
// here. Not sure if the added code overhead would outweight having
// one fourth of the coefficients.
// Observation 2: Linear interpolation could be used to improve
// result precision.
unsigned int i = std::rint(angle / (2*M_PI) * (N - 1));
return this->values[i];
}
private:
std::array<std::complex<Float>, N> values;
};
}