Skip to content

Instantly share code, notes, and snippets.

@orlp
Created March 5, 2012 18:38
Show Gist options
  • Select an option

  • Save orlp/1980227 to your computer and use it in GitHub Desktop.

Select an option

Save orlp/1980227 to your computer and use it in GitHub Desktop.
Fast sin function - IEEE754 only - double precision FPU mode only - (sizeof(double)/2) == sizeof(int) only - unreadable version :D
inline double fast_sin(register double x) {
register union {
double d;
int i;
} y;
register int k;
register double z;
y.d = x;
y.d *= 0.31830988618379067153776752674502872;
y.d += 6755399441055744.0;
k = y.i;
z = k;
z *= 3.14159265358979323846264338327950288;
x -= z;
z = x;
z *= x;
y.d = 0.00735246819687011731341356165096815;
y.d *= z;
y.d -= 0.16528911397014738207016302002888890;
y.d *= z;
y.d += 0.99969198629596757779830113868360584;
x *= y.d;
k &= 1;
k *= 2;
z = k;
z *= x;
x -= z;
return x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment