Skip to content

Instantly share code, notes, and snippets.

@mikelikesbikes
Created December 11, 2010 00:01
Show Gist options
  • Save mikelikesbikes/737009 to your computer and use it in GitHub Desktop.
Save mikelikesbikes/737009 to your computer and use it in GitHub Desktop.
function optimized_sin(x) {
while(x <= -2*Math.PI || x >= 2*Math.PI) {
if(x < 0) {
x += 2*Math.PI;
} else {
x -= 2*Math.PI;
}
}
return Math.sin(x);
}
optimized_sin(2*Math.PI) // => 0
optimized_sin(-2*Math.PI) // => 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment