Created
March 23, 2018 11:12
-
-
Save simonwittber/c3b63e71029719ccc8e084f69d00d293 to your computer and use it in GitHub Desktop.
A fast and accurate Sin for C#
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
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