Skip to content

Instantly share code, notes, and snippets.

@simonwittber
Created March 23, 2018 11:12
Show Gist options
  • Save simonwittber/c3b63e71029719ccc8e084f69d00d293 to your computer and use it in GitHub Desktop.
Save simonwittber/c3b63e71029719ccc8e084f69d00d293 to your computer and use it in GitHub Desktop.
A fast and accurate Sin for C#
float Sin(float x)
{
while (x < -3.14159265f)
x += 6.28318531f;
while (x > 3.14159265f)
x -= 6.28318531f;
float sin;
var xZ = x < 0 ? -1 : 1;
sin = 1.27323954f * x - xZ * .405284735f * x * x;
var sinZ = sin < 0 ? -1 : 1;
sin = .225f * (sin * sinZ * sin - sin) + sin;
return sin;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment