Created
June 13, 2020 11:37
-
-
Save dernatsch/9a8918ffe440ebc12421c93143a04238 to your computer and use it in GitHub Desktop.
Sine lookup-table generated at compile time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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