Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. template <typename T, int N, typename G>
  2. constexpr std::array<T, N> generate_array(G g) {
  3. std::array<T, N> result{};
  4. for (int i = 0; i < N; ++i)
  5. result[i] = g(i);
  6. return result;
  7. }
  8.  
  9. constexpr double cube(double x) { return x * x * x; }
  10.  
  11. // Based on the triple-angle formula: sin(3x) = 3*sin(x) - 4*sin^3(x)
  12. constexpr double sine_impl(double x) {
  13. constexpr double tol = 0.0001;
  14. return x < tol ? x : 3 * (sine_impl(x / 3.0)) - 4 * cube(sine_impl(x / 3.0));
  15. }
  16.  
  17. constexpr double sine(double x) {
  18. return sine_impl(x < 0 ? -x + M_PI : x);
  19. }
  20.  
  21. constexpr auto v = generate_array<double, 1024 * 1024>(sine);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement