Skip to content

Instantly share code, notes, and snippets.

@matwey
Last active October 20, 2015 16:54
Show Gist options
  • Save matwey/6f006e7c88710780fdac to your computer and use it in GitHub Desktop.
Save matwey/6f006e7c88710780fdac to your computer and use it in GitHub Desktop.
sin/cos series
#include <iostream>
#include <cmath>
int main(int argc, char** argv) {
const size_t n = 10000000;
double phi = 0.5;
double cos1 = std::cos(phi);
double sin1 = std::sin(phi);
double cosi = cos1;
double sini = sin1;
for(std::size_t i = 2; i < n; ++i) {
// double tmp = cos1*cosi - sin1*sini; // new cosi
// sini = sin1*cosi + cos1*sini;
// cosi = tmp;
double sinc = std::sin(i*phi);
double cosc = std::cos(i*phi);
std::cout << i << " " << sinc << " " << cosc << std::endl;
// std::cout << i << " " << 2 * (sini-sinc) / (sini+sinc) << " " << 2 * (cosi-cosc) / (cosi+cosc) << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment