Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename T, int N, typename G>
- constexpr std::array<T, N> generate_array(G g) {
- std::array<T, N> result{};
- for (int i = 0; i < N; ++i)
- result[i] = g(i);
- return result;
- }
- constexpr double cube(double x) { return x * x * x; }
- // Based on the triple-angle formula: sin(3x) = 3*sin(x) - 4*sin^3(x)
- constexpr double sine_impl(double x) {
- constexpr double tol = 0.0001;
- return x < tol ? x : 3 * (sine_impl(x / 3.0)) - 4 * cube(sine_impl(x / 3.0));
- }
- constexpr double sine(double x) {
- return sine_impl(x < 0 ? -x + M_PI : x);
- }
- constexpr auto v = generate_array<double, 1024 * 1024>(sine);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement