Skip to content

Instantly share code, notes, and snippets.

@acdimalev
Created January 15, 2011 05:20
Show Gist options
  • Save acdimalev/780718 to your computer and use it in GitHub Desktop.
Save acdimalev/780718 to your computer and use it in GitHub Desktop.
#define pi 3.1415926535897932
double sin(double a) {
double y;
double x = a / (pi / 2);
int fol = x;
int neg = (int)(x / 2) & 1;
int inv = (int)x & 1;
x = x - fol; // fold
x = (1 - inv) * x + inv * (1 - x); // invert?
a = x * (pi / 2);
y = a * (1 - a*a/6 * (1 - a*a/20 * (1 - a*a/42 * (1 - a*a/72 *
(1 - a*a/110 * (1 - a*a/156 * (1 - a*a/210 * (1 - a*a/272 *
(1 - a*a/342 * (1 - a*a/420))))))))));
y = neg * -y + (1 - neg) * y; // negate?
return y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment