Created
March 5, 2012 12:09
-
-
Save orlp/1978092 to your computer and use it in GitHub Desktop.
Ultra fast IEEE754 double-precision mode sin function
This file contains hidden or 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
| double cc_sin(double x) { | |
| const double a = 0.00735246819687011731341356165096815; | |
| const double b = -0.16528911397014738207016302002888890; | |
| const double c = 0.99969198629596757779830113868360584; | |
| double x2; | |
| union { | |
| double d; | |
| long i; | |
| } dtoi_hack; | |
| /* find offset of x from the range -pi to pi */ | |
| dtoi_hack.d = CC_1_PI * x + 103079215104.5; | |
| dtoi_hack.i >>= 16; | |
| x -= dtoi_hack.i * CC_PI; | |
| x2 = x*x; | |
| x *= (c + x2*(b + a*x2)); | |
| /* if x is in an odd pi count we must flip */ | |
| x -= (2 * (dtoi_hack.i & 1)) * x; /* trick for r = (k % 2) == 0 ? r : -r; */ | |
| return x; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment