Last active
October 12, 2018 08:26
-
-
Save benhall-7/816285b7578f79e8016a487710d66e18 to your computer and use it in GitHub Desktop.
Sine implementation
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 Sine(float x) { | |
if (fabs(x) > 0.0002441406) | |
{ | |
if (fabs(x) < 0.7853982) | |
{ | |
float sq = x * x; | |
x *= ((sq * -0.0001950181 + 0.008332016) * sq + -0.16666651) * sq + 1.0; | |
} | |
else if (x *= 0.6366197 > 1.0737418E+09) | |
x = 0; | |
else | |
{ | |
int qtrPeriod = (int)(x < 0 ? x - 0.5 : x + 0.5); | |
//float modulo | |
x -= IntToFloat(qtrPeriod); | |
if (qtrPeriod & 0x1) | |
{ | |
//crest and trough | |
float sq = x * x; | |
x = ((sq * -0.020398581 + 0.25359493) * sq + -1.2336967) * sq + 1.0; | |
} | |
else | |
{ | |
//in between | |
float sq = x * x; | |
x *= ((sq * -0.004601656 + 0.07968003) * sq + -0.64596341) * sq + 1.5707964; | |
} | |
//Other side of the circle | |
if (qtrPeriod & 0x2) | |
x = -x; | |
} | |
} | |
return x; | |
} | |
float IntToFloat(int arg) { | |
return (float)arg; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment