root / proj / fast_math.c @ 169
History | View | Annotate | Download (796 Bytes)
1 | 168 | up20180642 | #include "fast_math.h" |
---|---|---|---|
2 | |||
3 | #include <math.h> |
||
4 | |||
5 | double fm_sin(double x){ |
||
6 | if(x < 0.0) return -fm_sin(-x); |
||
7 | if(x > 2.0*M_PI) return fm_sin(x-2.0*M_PI); |
||
8 | if(x > M_PI) return -fm_sin(x-M_PI); |
||
9 | if(x > 0.5*M_PI) x = M_PI - x; |
||
10 | double x2 = x*x;
|
||
11 | double x3 = x*x2;
|
||
12 | double x5 = x3*x2;
|
||
13 | //double x7 = x5*x2;
|
||
14 | return x-x3*0.1666666666666666+x5*0.008333333333333333;//-x7*0.0001984126984127; |
||
15 | } |
||
16 | |||
17 | double fm_cos(double x){ |
||
18 | if(x < 0.0) x = -x; |
||
19 | if(x > 2.0*M_PI) return fm_cos(x-2.0*M_PI); |
||
20 | if(x > M_PI) x = 2.0*M_PI-x; |
||
21 | if(x > 0.5*M_PI) return -fm_cos(M_PI-x); |
||
22 | double x2 = x*x;
|
||
23 | double x4 = x2*x2;
|
||
24 | double x6 = x4*x2;
|
||
25 | //double x8 = x4*x4;
|
||
26 | return 1.0-x2*0.5+x4*0.041666666666666666-x6*0.00138888888888888888;//+x8*0.000024801587; |
||
27 | } |