Skip to content

Instantly share code, notes, and snippets.

@dernatsch
Created June 13, 2020 11:37
Show Gist options
  • Save dernatsch/9a8918ffe440ebc12421c93143a04238 to your computer and use it in GitHub Desktop.
Save dernatsch/9a8918ffe440ebc12421c93143a04238 to your computer and use it in GitHub Desktop.
Sine lookup-table generated at compile time.
#include <iostream>
#include <cmath>
template<int size>
struct SinTable {
constexpr SinTable() : values() {
for (int i = 0; i < size; i++) {
double angle = (M_PI*2)*(((double)i)/size);
values[i] = sin(angle);
}
}
double values[size];
};
static const SinTable<4096> table;
int main(int argc, char *argv[]) {
for (const auto v : table.values) {
std::cout << v << '\n';
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment