Skip to content

Instantly share code, notes, and snippets.

@kevinmoran
Last active October 9, 2019 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinmoran/c15263a8517ff43d783b25a49b4d7770 to your computer and use it in GitHub Desktop.
Save kevinmoran/c15263a8517ff43d783b25a49b4d7770 to your computer and use it in GitHub Desktop.
Sin Approximation
// From: https://web.archive.org/web/20080228213915/http://www.devmaster.net/forums/showthread.php?t=5784
float sinApprox(float x)
{
const float kPI32 = 3.14159265359f;
const float B = 4/kPI32;
const float C = -4/(kPI32*kPI32);
float y = B * x + C * x * abs(x);
#ifdef EXTRA_PRECISION
//const float Q = 0.775;
const float P = 0.225;
y = P * (y * abs(y) - y) + y; // Q * y + P * y * abs(y)
#endif
return y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment